shang
shang

Reputation: 23

Display vertical fractional numbers in UILabel or text view

I'm trying to display fractional numbers in an iPhone app, e.g. 12 and 3/81 should be displayed as the number "12" followed by the numerator "3" on top, a horizontal line, and the denominator "81" at the bottom.

I would greatly appreciate if anyone could advise me on how to achieve this. Should I subclass a UILabel and do custom drawing of the fraction, or should I subclass a UITextView?

Is there any sample code somewhere that shows how such custom drawing of UILabel or UITextView can be done?

Upvotes: 2

Views: 1063

Answers (1)

memmons
memmons

Reputation: 40492

Create a UIView subclass called FractionView with labels representing the numerator, the denominator and the separator (slash). Create numerator and denominator properties for the view to store the values you pass and set the labels accordingly. You can then drop this view anywhere you need to display fractions.

Upvotes: 1

Related Questions