-1
如何在objective-c中使用自動佈局時將具有特定顏色和厚度的邊框添加到UIView?Objective-c:如何使用自動佈局將邊框添加到UIView
如何在objective-c中使用自動佈局時將具有特定顏色和厚度的邊框添加到UIView?Objective-c:如何使用自動佈局將邊框添加到UIView
此功能將與特定的顏色和厚度的邊框添加到一個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];
希望你利用它所有的任何邊界。
對於那些低估我問題和答案的人,你能解釋一下爲什麼嗎?這是一個非常有用的功能! –