2012-02-04 233 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