UIButton query in swift IOS

北城余情 提交于 2020-01-05 04:35:28

问题


I have a button which is set at 62,62 square. I have an image which is 40,40 square.

I want the image in the button (which is easy and done), but I want it at the top of the button frame and I want some text at the bottom. So it looks like this :

Any idea how to do this in swift ?

I have got so far :

button.backgroundColor = UIColor(red: 0.13, green: 0.48, blue: 0.81, alpha: 1.0)
button.tag = i
button.imageView?.image
button.setImage(image, forState: .Normal)
button.setTitle("Test", forState: UIControlState.Normal)

The test setTitle, comes to the right of the image as ... form. Anyone can advise ?


回答1:


Using the interface builder;

  • set the image to the Background property of the button. Using code it is button.setBackgroundImage

  • from Control section set the horizontal alignment of the text to Bottom. Using code it is button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentBottom



来源:https://stackoverflow.com/questions/28027634/uibutton-query-in-swift-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!