2012-02-04 204 views
2

我正试图在圆形矩形按钮中放置箭头符号。我打算使用它作为反向/撤消按钮..如何去做呢?如何在圆形矩形按钮中添加箭头图标

是这样的吗?

- (IBAction)ReversePressed:(id)sender { 
    UIImage *image = [UIImage imageNamed:@"arrow.png"]; 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [button setImage:image forState:UIControlStateNormal]; 
} 

回答

2

使其自定义。如果你想它的边角圆,进口QuartzCore框架,将它添加到您的.h或.m文件:

#import <QuartzCore/QuartzCore.h>: 

viewDidLoad

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    UIImage *image = [UIImage imageNamed:@"arrow.png"]; 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [button setImage:image forState:UIControlStateNormal]; 

    // this is the code to make the button's corners round   
    [button setCornerRadius:cornerRadiusParam]; 
    [button setMasksToBounds:YES]; 

} 
+0

我在哪里添加这个?在(IBAction)的代码中呢? – lakesh 2012-02-04 17:15:42

+0

在'viewDidLoad'或任何你正在创建你的按钮 – 2012-02-04 17:16:23

+0

感谢您的帮助..真的很感激它... – lakesh 2012-02-04 17:17:17

2

最简单的答案就是使用Unicode字符。例如,您可以使用U + 21B6↶ANTICLOCKWISE顶部SEMICIRCLE箭头(在源代码中输入@"\u21b6")。或者你可以使用U + 21E6⇦左翼白箭头。 This PDF显示Unicode箭头字符范围。您还可以使用Mac OS X字符查看器来浏览它们。

如果您愿意需要iOS 5,还有表情符号字符⬅。

+0

所以它会去UIButton * button = @“\ u21b6”;? – lakesh 2012-02-04 17:40:50

+0

不需要。您必须设置按钮的'titleLabel.text'属性。您可能还需要设置按钮的“titleLabel.font”属性来调整箭头的大小。 – 2012-02-04 17:44:03

+0

如何设置titleLabel.text?对不起,我对此很新... – lakesh 2012-02-04 18:06:32