这是vIEwDIDLoad中的代码:
btArtAndPainting = [UIbutton buttonWithType:UIbuttonTypeCustom];btArtAndPainting.backgroundcolor = [[UIcolor cyancolor] colorWithAlphaComponent:1.00f];btArtAndPainting.translatesautoresizingMaskIntoConstraints = NO;self.vwContainer.translatesautoresizingMaskIntoConstraints = NO;[self.vwContainer addSubvIEw:btArtAndPainting];[btArtAndPainting setimage:[UIImage imagenamed:kimgcategoryArtAndPaintingnormal] forState:UIControlStatenormal];[btArtAndPainting setimage:[UIImage imagenamed:kimgcategoryArtAndPaintingHighlighted] forState:UIControlStateHighlighted];[btArtAndPainting setTitle:@"Art and Painting" forState:UIControlStatenormal];[btArtAndPainting setTitle:@"Art and Painting" forState:UIControlStateHighlighted];btArtAndPainting.tintcolor = [UIcolor redcolor];btArtAndPainting.TitleLabel.Font = [UIFont systemFontOfSize:10.00f];btArtAndPainting.TitleLabel.textcolor = [UIcolor whitecolor];btArtAndPainting.TitleLabel.textAlignment = NSTextAlignmentCenter;btArtAndPainting.TitleLabel.lineBreakMode = NSlineBreakByWorDWrapPing | NSlineBreakByTruncatingTail;btArtAndPainting.TitleLabel.numberOflines = 0;btArtAndPainting.imageEdgeInsets = UIEdgeInsetsMake(0.00f,8.00f,20.00f,8.00f);btArtAndPainting.TitleEdgeInsets = UIEdgeInsetsMake(32.00f,0.00f,0.00f);NSArray *constraintsWIDth = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[btArtAndPainting(60)]|" options:0 metrics:nil vIEws:vIEwDictionary];NSArray *constraintsHeight = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[searchbar]-10-[btArtAndPainting(60)]" options:0 metrics:nil vIEws:vIEwDictionary];[self.vwContainer addConstraints:constraintsHeight];[self.vwContainer addConstraints:constraintsWIDth];[btArtAndPainting layoutIfNeeded];[btArtAndPainting needsUpdateConstraints];
问题是文本根本不显示(在正常和突出显示的状态下).请参阅下面的链接图像.
如何使用UIEdgeInset为文本腾出空间?我也试过创建一个UIbutton类,但效果大致相同.
CGfloat spacing = 1.0;CGSize imageSize = btArtAndPainting.imageVIEw.frame.size;btArtAndPainting.TitleEdgeInsets = UIEdgeInsetsMake(0.0,- imageSize.wIDth,- (imageSize.height + spacing),0.0);CGSize TitleSize = btArtAndPainting.TitleLabel.frame.size;btArtAndPainting.imageEdgeInsets = UIEdgeInsetsMake(- (TitleSize.height + spacing),0.0,- TitleSize.wIDth);
希望这可以帮助..
总结以上是内存溢出为你收集整理的ios – 创建UIButton(UIButtonTypeCustom),顶部带有图像,底部带有AutoLayout标签全部内容,希望文章能够帮你解决ios – 创建UIButton(UIButtonTypeCustom),顶部带有图像,底部带有AutoLayout标签所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)