Scrungepipes
Scrungepipes

Reputation: 37581

Any way to make text in all buttons/action of a UIAlertController bold?

I have a requirement that the text in the buttons of a UIAlertController should be set to bold for every button (as opposed to the standard iOS behavior which is that the button assigned the style cancel is bold, or that for which preferredAction has been set is bold. The requirement is that all button text should be bold).

Is there a way to achieve this using a UIAlertController? Or will I be forced to created a custom dialog using a UIView?

There's plenty of past questions/answers on manipulating the body text for a UIAlertController using an attributed string, but I've not found anything for doing the equivalent for the text of the action buttons of an UIAlertController.

Upvotes: 0

Views: 953

Answers (2)

matt
matt

Reputation: 534958

Or will I be forced to created a custom dialog using a UIView?

Yes, that’s it. But it’s very easy, and gives you much more power and flexibility than UIAlertController. There are lots of sample projects out there, and once you’ve used one you may never go back to UIAlertController again!

Upvotes: 1

Ankit Jayaswal
Ankit Jayaswal

Reputation: 5679

Buttons on UIAlertController are of UIAlertAction. There are no any setter methods on any property of UIAlertAction available, so you can't change the button text to bold.

Even title have to be String type, it doesn't accept NSAttributedString. So you should go with a custom dialog using a UIView.

Apple class reference for UIAlertAction:

@available(iOS 8.0, *)
open class UIAlertAction : NSObject, NSCopying {

    public convenience init(title: String?, style: UIAlertActionStyle, handler: ((UIAlertAction) -> Swift.Void)? = nil)

    open var title: String? { get }

    open var style: UIAlertActionStyle { get }

    open var isEnabled: Bool
}

Upvotes: 1

Related Questions