2017-07-31 67 views
0

我需要把UIView的一個標誌,只有3個邊界可見或突出顯示如圖所示下面image.How做這在Objective-C的的。 如果例如提供,這將是很好。如何把具有標籤3側邊框

enter image description here

+0

嘿,你可以嘗試檢查此鏈接。 https://ktrkathir.wordpress.com/2015/09/18/how-to-draw-or-set-a-border-for-particular-side-of-uitextfield-in-ios/comment-page-1/ –

+0

下面的鏈接可能是有用的you.https://stackoverflow.com/a/29033559 –

回答

0
- (CALayer *)prefix_addUpperBorder:(UIRectEdge)edge color:(UIColor *)color thickness:(CGFloat)thickness 
{ 
    CALayer *border = [CALayer layer]; 

    switch (edge) { 
     case UIRectEdgeTop: 
      border.frame = CGRectMake(0, 0, CGRectGetWidth(self.frame), thickness); 
      break; 
     case UIRectEdgeBottom: 
      border.frame = CGRectMake(0, CGRectGetHeight(self.frame) - thickness, CGRectGetWidth(self.frame), thickness); 
      break; 
     case UIRectEdgeLeft: 
      border.frame = CGRectMake(0, 0, thickness, CGRectGetHeight(self.frame)); 
      break; 
     case UIRectEdgeRight: 
      border.frame = CGRectMake(CGRectGetWidth(self.frame) - thickness, 0, thickness, CGRectGetHeight(self.frame)); 
      break; 
     default: 
      break; 
    } 

    border.backgroundColor = color.CGColor; 

    [self.layer addSublayer:border]; 

    return border; 
}