I want to make a custom UIBarButtonItem to represent the Done button.
I want to able to internationalize the app, so I want the text to be directly editable. To take into account different lengths of the “Done” Label, I’ve designed an stretchableImage. Is it possible to directly change the default edit button background or is a custom UIBarButtonItem needed? If so, what would be the way to dynamically resize the background stretchableImage according to the length of the label?
I want to make a custom UIBarButtonItem to represent the Done button. I want
Share
If you are targeting iOS 5.0 only, you can change the default appearance with the new
UIAppearancemethods,-setBackButtonBackgroundImage:forState:barMetrics:specifically.If you need to support older versions of iOS, you should subclass
UIBarButtonItem, add aUIButtoninstance variable, create it and call–initWithCustomView:in theinitmethod of yourUIBarButtonItem. That’s becauseUIBarButtonItemis not a subclass ofUIViewand you can’t draw your custom images in it. You should also set thewidthproperty of yourUIBarButtonItemmanually.PS. Don’t forget to override
targetandactionproperties of your subclass to work with yourbuttoninstance.