Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios setTitleColor:UIButton子类initWithCoder中的状态未设置颜色_Ios_Objective C_Uibutton_Xcode5 - Fatal编程技术网

Ios setTitleColor:UIButton子类initWithCoder中的状态未设置颜色

Ios setTitleColor:UIButton子类initWithCoder中的状态未设置颜色,ios,objective-c,uibutton,xcode5,Ios,Objective C,Uibutton,Xcode5,我对自定义.xib文件中包含的UIButton进行了子类化,并试图通过initWithCoder方法为每个状态设置按钮的标题颜色。目前,我有: -(id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if(self) { self.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0); [self setTitleColor:[

我对自定义.xib文件中包含的UIButton进行了子类化,并试图通过initWithCoder方法为每个状态设置按钮的标题颜色。目前,我有:

-(id)initWithCoder:(NSCoder *)aDecoder {
  self = [super initWithCoder:aDecoder];
  if(self) {
    self.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [self setTitleColor:[UIColor navigationLabelColor] forState:UIControlStateNormal];
  }
  return self;
}
但是,标题颜色不变,但边缘插图不变。我做错什么了吗


PS:我应该补充一点,自定义xib用于不同的元素,但在该xib中有几个此按钮的实例。

子类化UIButton由于UIButtonType而不是直接的,UIButtonType似乎默认为UIButtonTypeCustom用于简单的子类化。更改帧/边界似乎可以很好地工作,但其他一些方面不行

就我个人而言,我已经成功地为我的需要使用UIButtonTypeCustom子类,主要添加了背景图像拉伸

您需要找到另一种方法来满足您的需求,或者深入研究UIButton的子类化


由于对UIButton子类化进行了搜索,您将发现大量信息,包括表示基本上不需要的注释。看看这个。

你试过其他颜色吗?谢谢你的回答-是的,我试过了。[UIColor greenColor]没有任何区别。许多开发人员都会同意不将UIButton子类化,因为它非常复杂,所以您可以尝试其他方法options@RetroUIButton的成功子类化取决于您的需要,并不总是不合适的。@Zaph是的,我同意:谢谢+1嘿,Zaph,谢谢你的回复,很抱歉花了这么长时间才回复你。我遇到的问题是标题是属性字符串,因此要更改属性字符串的属性,必须调用:setAttributedTitle:forState:。尽管如此,还是要谢谢你。