IOS developer based in barcelona.

UIButton with Right Image

A few months ago I was working on a new app. It uses data from Instagram to display user insights, media insight, etc. It only will be available for Instagram Business Accounts. It was fun because I've learned a lot, using a new architecture, testing, facebook/instagram API graph, webhooks, firebase cloud functions, etc.

Simulator Screen Shot - iPhone 8 Plus - 2018-06-03 at 16.41.50.png

I'll create some posts about basic tips that I've used, so, the first one is super simple, is adding a button with text and image.

The goal is creating a button with text and a right image like the following image

Screen Shot 2018-06-03 at 16.55.24.png
public lazy var seeAllButton: UIButton = {
        let button = UIButton(type: .system)
        button.setTitle("See all", for: .normal)
        button.setImage(Stylesheet.image(.arrowRight), for: .normal)
        button.semanticContentAttribute = .forceRightToLeft
        button.titleLabel?.font = Stylesheet.font(.extraInfoLight)
        button.setTitleColor(Stylesheet.color(.black), for: .normal)
        button.tintColor = Stylesheet.color(.black)
        button.addTarget(self, action: #selector(didTapOnSeeAllButton), for: .touchUpInside)
        button.translatesAutoresizingMaskIntoConstraints = false
        return button
    }()

easy right? it's not a big deal, the most important line is

button.semanticContentAttribute = .forceRightToLeft

without the last line, the result would be

Screen Shot 2018-06-03 at 17.03.01.png

Conclusion

I showed how to create a UIButton with text and a right image

I'm all ears to know your feedback, thanks for reading! 😃

Strong typed Ids in Swift

DateFormatter to display relative dates: today, yesterday, etc