【发布时间】:2014-06-10 17:18:53
【问题描述】:
我尝试的是这样的:-
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[self.view addSubview:btn];
btn.translatesAutoresizingMaskIntoConstraints = NO;
[btn addTarget:self action:@selector(bringUpNextViewController:)
forControlEvents:UIControlEventTouchUpInside];
btn.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
[btn setTitle:@"8" forState:UIControlStateNormal];
[self.view layoutIfNeeded];
NSLog(@"button size : %@", NSStringFromCGSize(btn.frame.size));
作为输出,我得到了这个:
button size : {30, 29}
然后我给了setTitle 字符串。按钮宽度仍然是 30。
那么为什么总是这样呢?
我还尝试提供high compression resistance priority 和high content hugging priority。不会缩水。
问题还在于我想仅根据其内容来减小按钮的宽度,而没有给出任何固定宽度。
我可以获取文本的宽度并为按钮指定宽度,但如果按钮占用了内容宽度,我也不需要这样做。
编辑:
导致宽度为30 的也不是插图。鬼值。
【问题讨论】:
标签: ios uibutton autolayout