1

I want to implement custom text fields. Here is a screenshot of what I want to implement:

enter image description here

So I have a UITableView with cells, and in each cell I have several text fields: one for date, one for name, one for theme, and one for text. But the UI requires theme and text to be next to each other (as can you see in the picture). I wanted to implement this as a single UITextField, but as far as I know, UITextField supports only one type of font. So maybe someone will give me a piece of advice how to implement the design shown in the screenshot — do I have to draw custom text fields, or are there simpler solutions? Any code samples or propositions would be helpful.

Ben Klein
  • 1,719
  • 3
  • 18
  • 41
MainstreamDeveloper00
  • 8,436
  • 15
  • 56
  • 102
  • Can you place the theme textfield on top of the main text, so that they both occupy some of the same viewing rectangle? If so, you might be able to calculate on the fly how much space the theme actually takes up on that first line, and programatically add blank spaces to the text field. – Austin Mullins Jan 14 '13 at 18:36
  • 1
    check this out http://stackoverflow.com/questions/3586871/bold-non-bold-text-in-a-single-uilabel – alex Jan 14 '13 at 18:44
  • Do you want to just display this text or is it supposed to be editable? From your screenshot it doesn’t look like it is supposed to be editable. And then you don’t need an `UITextField`, just an `UILabel` for each part. – Sven Jan 14 '13 at 18:44

1 Answers1

1

For iOS 6:

You can set a UITextField's attributed string:

@property(nonatomic,copy) NSAttributedString *attributedText;

I suggest to use a NSMutableAttributedString and to exploit polymorphism.

A mutable attributed string can hold vary attributes for each piece of the string. So you can add an attribute only for a certain range of the string with this method:

- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)aRange;

For iOS 5:

Use directly this UITextField's property:

- (void)setAttributes:(NSDictionary *)attributes range:(NSRange)aRange;
Ramy Al Zuhouri
  • 21,580
  • 26
  • 105
  • 187