更改按钮文本时如何防止重叠?

时间:2015-08-25 17:09:47

标签: ios objective-c

我有以下代码来更改"按钮" to"按我!":

[self.aButton setTitle:@"Press Me!" forState:UIControlStateNormal];

但是,当我运行模拟器时,它会显示两者的文本并重叠。我试着收紧按钮,但是在我再次运行模拟器之后,有两个按钮,一个是默认文本"按钮",另一个是"按我!" 。我还尝试从实用工具面板中删除该按钮的默认文本,但这也没有用。

我该如何解决这个问题?

ViewController.h
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIButton *aButton;

@end

ViewController.m
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.aButton setTitle:@"Press Me!" forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)buttonPressed:(id)sender {
    self.view.backgroundColor = [UIColor orangeColor];
}

@end

0 个答案:

没有答案