IOS 创建圆角矩形按钮及设置阴影等其他属性

来源:互联网 发布:微信服务号 域名备案 编辑:程序博客网 时间:2024/04/30 20:25

今天做一个圆角按钮(ios 8.4), 使用下边代码没什么反应。

UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];


最终如下方式设置:

    UIButton* btn = [[UIButton alloc] init];    btn.backgroundColor = [[UIColor alloc] initWithRed:153/255.0 green:102/255.0 blue:51/255.0 alpha:0.99];    btn.frame = CGRectMake(0, 0, fBtnWidth, fBtnHeight);    [btn setTitle:@"do-sth" forState:UIControlStateNormal];    btn.titleLabel.textColor = [UIColor whiteColor];    [btn.titleLabel setFont:[UIFont fontWithName:@"System" size:19.0f]];    btn.layer.cornerRadius = 10.0f;    btn.layer.shadowOffset = CGSizeMake(1, 1);    btn.layer.shadowColor = [UIColor brownColor].CGColor;    btn.layer.shadowRadius = 4.0f;    btn.layer.shadowOpacity = 0.8f;    btn.layer.borderWidth = 1.2f;     [self.view addSubview:btn];


0 0
原创粉丝点击