2 mapmapm MapMapM 于 2013.07.31 13:45 提问

在自定义按钮中设置文本

在自定义按钮使用自定义图片。然后我想设置标题时弄不上。

代码:

- (void)viewDidLoad
{
    UIImage *backButtonImage = [UIImage imageNamed:@"button.png"];
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [backButton setImage:backButtonImage forState:UIControlStateNormal];
    [backButton setTitleColor:[UIColor colorWithRed:0.49 green:0 blue:0 alpha:1] forState:UIControlStateNormal];
    [backButton setTitle:@"DONE" forState:UIControlStateNormal];
    backButton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
    [backButton addTarget:self action:@selector(goBackOne) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.hidesBackButton = YES;//hide original back button
}

效果图片:

CSDN移动问答

1个回答

karas117
karas117   2013.07.31 14:30
已采纳

[backButton setBackgroundImage:backButtonImage forState:UIControlStateNormal];

Csdn user default icon
上传中...
上传图片
插入图片