简体   繁体   English

如何在 Swift 中将 label 添加到 uibutton?

[英]How to Add label to uibutton in Swift?

I want to achieve that look of my button as shown?我想实现我的按钮的外观,如图所示? The right side of button which contains arrow (>) needs to be a simple label with that text.包含箭头 (>) 的按钮右侧需要是带有该文本的简单 label。 How can i do that?我怎样才能做到这一点? Is there anyway?到底有没有? I have checked many possibilities like taking a UIView and then adding button and labels inside it.我已经检查了许多可能性,例如使用 UIView,然后在其中添加按钮和标签。 I wanna know is that the only solution or there exist any other good one.我想知道的是唯一的解决方案或存在任何其他好的解决方案。 Thanks.谢谢。 在此处输入图像描述

Do you use Masonry or SnapKit?您使用 Masonry 还是 SnapKit? Try this:尝试这个:

let label = UILabel()
label.text = ">"
button.addSubview(label)
label.snp.makeConstraints {
    $0.right.equalToSuperview()
    $0.centerY.equalToSuperview()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM