Calling self.titleLabel within [UIButton titleRectForContentRect:] causes infinite loop

Number:rdar://51294267 Date Originated:
Status:Open Resolved:
Product:UIKit Product Version:12.2
Classification:Crash Reproducible:Always
We noticed that when using self.titleLabel within UIButton's titleRectForContentRect: method, this will result in an infinite loop. We have to use the titleLabel property here though due to another bug in the iOS SDK. Nevertheless, using self.titleLabel here shouldn't result in an infinite loop and therefore a crash.

Steps to Reproduce:
Subclass UIButton, override titleRectForContentRect: method, add the super call, use self.titleLabel.numberOfLines for example. This will ultimately result in EXC_BAD_ACCESS (code=2, address=0x7ffee6c91ff0).

Expected Results:
Using self.titleLabel in -titleRectForContentRect: shouldn't cause an infinite loop.

Actual Results:
Using self.titleLabel in -titleRectForContentRect: causes an infinite loop.

iOS 12.2


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!