如何在ios中更改按钮的形状?

时间:2015-09-30 09:08:19

标签: ios objective-c uibutton

我想制作一个圆角按钮我应用了以下代码,但它不起作用。 Plz帮助我 enter image description here

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];

2 个答案:

答案 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;