我想制作一个圆角按钮我应用了以下代码,但它不起作用。 Plz帮助我
login = [UIButton buttonWithType:UIButtonTypeRoundedRect];
CGFloat xbuttonpadding = CGRectGetMinX(password.frame);
CGFloat ybuttonpadding = CGRectGetMaxY(password.frame) + xpadding;
CGFloat widthloginbutton = CGRectGetWidth(self.view.frame) - widthpassword;
CGFloat heightloginbutton = CGRectGetHeight(username.frame) +10;
login.frame= CGRectMake(xbuttonpadding, ybuttonpadding, widthloginbutton, heightloginbutton);
login.backgroundColor = [UIColor blueColor];
[login setTitle:@"login" forState:UIControlStateNormal];
[login addTarget:self action:@selector(show:) forControlEvents:UIControlEventTouchUpInside];
答案 0 :(得分:1)
首先在你的.m文件中导入它 -
#import <QuartzCore/QuartzCore.h>
然后在你的loadView方法中添加以下行
yourButton.layer.cornerRadius = 10; // this value vary as per your desire
yourButton.clipsToBounds = YES;
希望这适合你
答案 1 :(得分:0)
尝试:
login.layer.cornerRadius = 0.5f;
login.clipsToBounds = YES;