12 Jul 2019

Swift Tutorial: UIButton resize according to text length


Swift Tutorial: UIButton resize according to text length


In this tutorial, we will learn how to resize button while changing tittle of UIButton dynamically or programmatically in swift. When we create an UIButton in storyboard and set a large title to it in our ViewController class, the size of UIButton remain same as in the story board and title is showed dotted from the middle. In this tutorial, we will resolve this issue by overriding the interensicContent size of UIButton.

For this first we will create a custom class that inherits UIButton and there we will overirde the interinsicContentSize of the UIButton. Below is the code snippets of the custom class, we named it as "AdaptableSizeButton".


Since we have code for our custom class, in your storyboard change UIButton class to AdaptableSizeButton and see the results. If you nay concerns do post a comment for same.

No comments:

Post a Comment