0

我是新手,所以我无法上传图片,但是当我在 iOS 中自定义 backButtonItem 时遇到问题,我编写的代码:

UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backBtnImage = [UIImage imageNamed:@"backBtn.png"];
backBtn.frame = CGRectMake(0, 0, backBtnImage.size.width, backBtnImage.size.height);
[backBtn setBackgroundImage:backBtnImage forState:UIControlStateNormal];
backBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
[backBtn addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
[backBtn setTitle:@"Back" forState:UIControlStateNormal];
UIBarButtonItem *backBtnItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];

[backBtnItem setStyle:UIBarButtonItemStyleDone];
self.navigationItem.leftBarButtonItem = backBtnItem;

但是带有“back”的标题未在 backButton 上对齐。我如何对齐已自定义的后退按钮项的标题?

4

1 回答 1

0

试试这个:

backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
于 2012-10-11T09:50:02.807 回答