【发布时间】:2014-09-15 13:29:40
【问题描述】:
我正在使用SmileyBorg 的PureLayout 库来实现一些自动布局魔法。
如何添加UIButtonTypeCustom?
普通按钮将使用以下 Pure Layout UIButton 类方法初始化:
self.myButton = [UIButton newAutoLayoutView];
自定义UIButtons 初始化为
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
因为我不能做类似的事情
self.myButton = [[UIButton buttonWithType:UIButtonTypeCustom] newAutoLayoutView];
并且没有'buttonType'属性来设置初始化后 - 我如何组合 在 PureLayout 中创建自定义 UIButton 的这些步骤?
【问题讨论】:
-
顺便说一下,请注意
+[UIView newAutoLayoutView]方法实际上只做一件事(除了常规实例化):将translatesAutoresizingMaskIntoConstraints设置为NO。所以不要害怕使用普通的初始化程序,然后只需添加行view.translatesAutoresizingMaskIntoConstraints = NO之后。另一个专业提示:每当您在 UIView 上调用auto...API 之一(例如[view autoCenterInSuperview]),translatesAutoresizingMaskIntoConstraints属性会自动设置为 NO 用于您调用该方法的视图:) -
啊,太棒了——说得通。感谢@smileyborg 的回复!
标签: ios objective-c iphone uibutton autolayout