UIView,UIButton,UILabel,UIImageV
2018-08-21 本文已影响0人
ForstDragon
1,UIView
1,通过代码创建
UIView *inputAmountBGView = [[UIView alloc]init];
inputAmountBGView.frame = CGRectMake(20, 15, ScreenWidth - 40, 44);
inputAmountBGView.backgroundColor = [UIColor whiteColor];
inputAmountBGView.layer.borderColor = [UIColor colorWithRed:143/255.0 green:153/255.0 blue:181/255.0 alpha:0.5].CGColor;
2,UIButton
1,通过代码创建
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake((ScreenWidth/4)*3, 0,ScreenWidth/4, 44);
[button setTitle:@"确定" forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithRed:0/255.0 green:122/255.0 blue:255/255.0 alpha:0.5] forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithRed:0/255.0 green:122/255.0 blue:255/255.0 alpha:0.5] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(quedingBtnClick) forControlEvents:UIControlEventTouchUpInside];
3,UILabel
1,通过代码创建
UILabel *wanLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth - 45, 29, 15, 15)];
wanLabel.textColor = [UIColor colorWithRed:0/255.0 green:15/255.0 blue:48/255.0 alpha:1/1.0];;
wanLabel.font = [UIFont systemFontOfSize:15];
wanLabel.textAlignment = NSTextAlignmentCenter;//(中间对齐),NSTextAlignmentLeft(左对齐),NSTextAlignmentRight(右对齐)
wanLabel.text = @"万";
4,UIImageView
UIImageView * loanIconImgV = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 40,40)];
loanIconImgV.backgroundColor = [UIColor whiteColor];
loanIconImgV.image = [UIImage imageNamed:@"ic_qkf"];
5.1,设置圆角,边框的宽度,边框的颜色
1代码创建,以UIView为例,这几种的设置相同
//设置圆角,设置控制的高度的一半为半圆
testView.layer.cornerRadius = 10;
//剪切掉不要的部分
testView.clipsToBounds = YES;
//设置边框颜色
testView.layer.borderColor = [UIColor whiteColor].CGColor;
//设置边框宽度
testView.layer.borderWidth = 1.0f;
5.2,xib设置圆角,边框的宽度,边框的颜色
image.png
1,layer.cornerRadius ,注意该 key 对应 Value 的 type 应该设置为 String/Number
两种类型均可(代码设置弧度为:thisViewlayer.masksToBounds = YES)
2,layer.masksToBounds ,注意该 key 对应 Value 的 type 应该设置为 Boolean ,
当右侧出现对号时为YES(代码圆角为:thisView.layer.masksToBounds = YES)
3,layer.borderWidth ,注意该 key 对应 Value 的 type 应该设置为 String/Number
两种类型均可(代码设置边框宽度为:thisViewlayer.borderWidth = 2)
4,layer.borderColor , 注意该 key 对应 Value 的 type 应该设置为
Color(代码设置边框颜色:thisView.layer.borderColor = [UIColor
redColor].CGColor)
注意:因为在设置borderColor的时候,需要接受的是一个CGColor,而在 key Path中只有Color,其实就是 UIColor,类型是不对的,因此并没有正确显示想要展现的颜色.
因此这样的写法是有问题的.
通过添加一个CALayer的类扩展实现的,将key Path中设置的UIColor转换成为CGColor,为边框设置颜色,实现如下:
#import "CALayer+XibBorderColor.h"
#import <UIKit/UIKit.h>
@implementation CALayer (XibBorderColor)
- (void)setBorderColorWithUIColor:(UIColor *)color
{
self.borderColor = color.CGColor;
}
@end