简体   繁体   English

Swift - 如何以编程方式创建两个文本和图像之间的按钮?

[英]Swift - How can I create button with two texts and image between them programmatically?

How can I create this button programmatically: 如何以编程方式创建此按钮:

在此输入图像描述

I am already tried this: 我已经尝试过了:

    buttonLike.setImage(UIImage(named: "imageLikeForButton"), forState: UIControlState.Normal)

    buttonLike.setTitle("Like ", forState: UIControlState.Normal)

    buttonLike.tintColor = UIColor(red: 170.0/255.0, green: 170.0/255.0, blue: 170.0/255.0, alpha: 1.0)

    buttonLike.transform = CGAffineTransformMakeScale(-1.0, 1.0)
    buttonLike.titleLabel!.transform = CGAffineTransformMakeScale(-1.0, 1.0)
    buttonLike.imageView!.transform = CGAffineTransformMakeScale(-1.0, 1.0)

But it work only for one text and one image: 但它只适用于一个文本和一个图像:

在此输入图像描述

我认为最好创建一个UIView并使用gesturerecognizer进行操作(按键等)。

You can create an UIView and put everything in this view. 您可以创建一个UIView并将所有内容放在此视图中。 Then put a transparent button on the top of this view. 然后在此视图的顶部放置一个透明按钮。 I think this is an easier way. 我认为这是一种更简单的方法。

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

相关问题 如何以编程方式创建segue以在视图控制器之间传递信息 - Swift - How can I create a segue programmatically to pass info between view controllers - Swift 我可以在 swift 文本之间放置 UIButton 或 UITextField 或 UITextView - Can I put a UIButton or UITextField or UITextView between the texts in swift Swift:如何以编程方式在查看结束时设置按钮 - Swift:How can i set button at the end of View Programmatically 如何以编程方式禁用 swift 4 中的 iphone 主页按钮? - How can I programmatically disable iphone home button in swift 4? Swift 3如何以编程方式将图像链接到按钮 - Swift 3 How to programmatically link an image to a button 如何在Swift中以编程方式在图像上添加渐变层? - How can I programmatically add a Gradient Layer over an image in Swift? 如何在 swift 中使用 for 循环以编程方式创建按钮 - How to create a button programmatically with for loop in swift 依次显示两个相同的警报视图。 如何区分警报1和警报2的文本? - Two identical alert views shown in sequence. How can I differentiate between texts from alert 1 and alert 2? 如何创建函数序列并在Swift中循环? - How can I create a sequence of functions and loop them in Swift? Swift 360图片:如何在全景图片中添加按钮 - Swift 360 image: How i can add a button in a panoramic image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM