Yes, you can display the image and title in the same button if they are small enough to fit. The hard part comes when you need to deal with placement.
You can play with the contentVerticalAlignment and contentHorizontalAlignment properties of the UIButton (inherited from UIControl ).
You can also use the titleEdgeInsets and imageEdgeInsets properties to move the title and image from the placement they receive based on the alignment properties.
If you want a very precise or selective placement, I suggest overriding the methods titleRectForContentRect: and imageRectForContentRect: UIButton . This allows you to define frames for your name and image, and they are called whenever you need to lay out a button. One warning, if you want to reference self.titleLabel inside titleRectForContentRect: first make sure self.currentTitle defined. I get a bad access error, maybe the method is called the first time titleLabel is initialized.
ohnit Aug 09 '13 at 19:09 2013-08-09 19:09
source share