简体   繁体   中英

Custom UIButton in Objective-C

i want a view with some button, each button must have an image on the left, e bold title and under this, details in italic, is possible make this?

The only (stupid) way i've found is put 2 label over the button, is there any other way?

Thanks for any reply.

The cleanest way to have custom positioning of the image and label is to subclass UIButton and override -titleRectForContentRect: and -imageRectForContentRect: . Of course, UIButtons only have one label by default, so you'll need to add a second label (eg in -initWithFrame: / -initWithCoder: ) and lay it out in -layoutSubviews

You need to subclass a UIButton and in the – drawRect: method, do your custom drawing. You can pretty much draw whatever you like in it.

如果标题和详细信息具有动态性质,则必须制作自己的UIButton子类并重写drawRect方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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