【发布时间】:2014-09-18 14:27:04
【问题描述】:
我创建了一个 UIButton 的子类,在触摸时插入了一个动画视图,并通过 layoutSubviews 更改了我的 UIImage 和 UILabel 的位置。现在,当我在情节提要中创建六个这样的子类 UIButton 并在我的设备上运行应用程序时,我得到以下信息:
4 个 UIButton 似乎可以正常工作,但 5 个及以上似乎总是会影响我的 UILabel。为什么右侧 UIButton 的 UILabel 丢失了?
我认为 layoutSubviews 中发生了一些奇怪的事情,但我看不到。该方法的代码如下:
- (void)layoutSubviews {
[super layoutSubviews];
CGRect imageFrame = self.imageView.frame;
imageFrame = CGRectMake(truncf((self.bounds.size.width - imageFrame.size.width) / 2), 40.0f, imageFrame.size.width, imageFrame.size.height);
self.imageView.frame = imageFrame;
CGRect labelFrame = self.titleLabel.frame;
labelFrame = CGRectMake(self.frame.origin.x, self.bounds.size.height - labelFrame.size.height - 10.0f, self.frame.size.width, labelFrame.size.height);
self.titleLabel.frame = labelFrame;
self.titleLabel.textAlignment = NSTextAlignmentCenter;
}
有什么想法吗?
【问题讨论】:
-
如果您检查右侧按钮标签的框架,值是多少?标签尺寸不正确或位置不正确。查看框架会告诉您应该解决哪个问题。
-
你检查过你设置的框架吗?
标签: ios objective-c uibutton