2016-04-21 18 views

回答

2

此功能將與特定的顏色和厚度的邊框添加到一個UIView

- (void)addBorder:(UIView *)view toEdge:(UIRectEdge)edge withColor:(UIColor *)color withThickness:(float)thickness{ 
    UIView *border = [UIView new]; 
    border.backgroundColor = color; 
    [border setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin]; 
    switch (edge) { 
     case UIRectEdgeTop: 
      border.frame = CGRectMake(0, 0, view.frame.size.width, thickness); 
      break; 
     case UIRectEdgeBottom: 
      border.frame = CGRectMake(0, view.frame.size.height - thickness, view.frame.size.width, thickness); 
      break; 
     case UIRectEdgeLeft: 
      border.frame = CGRectMake(0, 0, thickness, view.frame.size.height); 
      break; 
     case UIRectEdgeRight: 
      border.frame = CGRectMake(view.frame.size.width - thickness, 0, thickness, view.frame.size.height); 
      break; 
     default: 
      break; 
    } 
    [view addSubview:border]; 
} 

使用

[self addBorder:yourView toEdge:UIRectEdgeTop withColor:[UIColor greenColor] withThickness:3.0f]; 

希望你利用它所有的任何邊界。