Reputation: 1181
Here is my problem: I have UITableView and I want to dynamically configure "THE Cell" text with different text fonts e.g. first line will be 12, Helvetica, Bold and the second line will be 10, Helvetica. Also note that number of lines is unknown and needs to be dynamically determined. Any help appreciated!
ps: Apparently question isn't understood well. I didn't mean to show each line in different cells. So think about only one cell and configuring the text for this particular cell. I have a dynamically determined number of lines for this cell so it could be 2 or 3 depending on the availability of the information. And I want this lines to have different fonts and different colors. One way to go for this is to have dynamic number of UILabel for the cell, but I would like to see if there is other options?
Upvotes: 1
Views: 2341
Reputation: 3154
I can't really answer this very well without an example pattern but here it goes:
In - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
add your customisations. Here's some examples:
1)
if (indexPath = 1) { //row 1
cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12]; //Important note: -Bold can vary per font. For example, Arial's bold variant is 'Arial-BoldMT'.
//change to needs
}
else if (indexPath = 2) { //row 2
//etc.
2)
if (indexPath <= 6) { //row 1-6
cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12]; //Important note: -Bold can vary per font. For example, Arial's bold variant is 'Arial-BoldMT'.
//change to needs
}
else if (indexPath >=7 && indexPath <=15) { //rows 7-15
//etc.
3)
///etc.
else if (indexPath >=84) { //rows 84 and over
cell.detailTextLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12];
}
Unless you have a specific pattern, it can be hard if you don't know how many rows there are. If you need any more help just comment below.
Upvotes: 3
Reputation: 48398
This is fairly trivial to do. Just set the content of the cells in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
You can adjust the font size, color, etc based on the indexPath
of the cell.
If you want a plethora of examples of what all is possible, then check out Apple's Table View Programming Guide.
Upvotes: 0