我想UILabel
在UIButton
. 这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[self addressSearch] setDelegate:self];
[[self worldMap] setDelegate:self];
self.boolPushButtonTapped = YES;
self.addressSearch.barStyle = 1;
//Create pushButton
self.pushButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.pushButton.frame = CGRectMake(106, 436, 110, 59);
[self.pushButton setBackgroundImage:[UIImage imageNamed:@"pushButton2.png"] forState:UIControlStateNormal];
[self.pushButton addTarget:self action:@selector(pushButtonTapped) forControlEvents:UIControlEventTouchUpInside];
//Label
self.distanceLabel = [[UILabel alloc] init];
self.distanceLabel.text = @"test";
[self.pushButton addSubview:self.distanceLabel];
[self.view addSubview:self.pushButton];
}
如果我不使用alloc
init
我会收到一个错误,并且如果我使用该标签中的文本不会改变。错误:
*** Assertion failure in -[NSLayoutConstraint constant], /SourceCache/Foundation/Foundation-992/Layout.subproj/NSLayoutConstraint.m:560
2012-10-01 14:01:01.889 RemindMe[1116:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '(null)'
我想在这个按钮内添加,因为有一个动画。
有什么建议么?