更改按钮的形状

时间:2014-03-24 05:16:36

标签: ios7 xcode5

我不知道如何重塑按钮。在xcode 5中,按钮形状最初是矩形。 但是现在我想让它圈起来。 我不知道如何实现这一点。请帮我。

4 个答案:

答案 0 :(得分:1)

非常简单

只需制作按钮的IBOutlet,然后将按钮角半径设为如下

[btn.layer setCornerRadius:10.0];

[btn setClipsToBounds:YES]; //write this if you are using image in button

确保您的按钮是正方形以获得完美的圆形 并将宽度的一半作为角半径

,如果您的按钮宽度为100.0且高度为100.0,则设置cornerradius 50.0 [btn.layer setCornerRadius:50.0];

答案 1 :(得分:0)

如果您需要圆形按钮,可以通过编程方式设置类型

button = [UIButton buttonWithType:UIButtonTypeInfoDark];

OR

你可以使用Interface Builder

enter image description here

注意:如果您需要自定义圆形按钮,请使用圆形图像作为按钮的bachgrounf图像 即,

[button setBackgroundImage:image forState:UIControlStateNormal]

答案 2 :(得分:0)

试试这个:

self.yourButton.clipsToBounds = YES;
self.yourButton.layer.cornerRadius = self.yourButton.frame.size.width / 2;//half of the width

确保按钮的宽度和高度相同,类型应该是自定义的。

答案 3 :(得分:0)

你可以这样做:

  1. 将按钮Type更改为Custom
  2. 为其设置圆形图像。
  3. 此外,这是another way to go