How do I accomplish something like this:
a table cell with multiple actions inside the text
(link to image, since I don't have enough point to paste images)
I want to be able to control what the bold text does (e.g. activate a segue) and I also want the cell itself to have a separate action.
Is this possible?
The text is dynamic, so the string lengths are not fixed.
Any help is much appreciated! (this is my first question of StackOverflow btw).
2 回答
0
检查下面的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSString *indexpath_str=[NSString stringWithFormat:@"%d",indexPath.row+1];
NSString *ordinary_string=[NSString stringWithFormat:@"This is %d",indexPath.row+1];
NSMutableAttributedString *attri_str=[[NSMutableAttributedString alloc]initWithString:ordinary_string];
int last=[indexpath_str length];
int begin=[ordinary_string length]-[indexpath_str length];
[attri_str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(begin,last)];
[attri_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30] range:NSMakeRange(begin, last)];
cell.textLabel.attributedText =attri_str;
return cell;
}
于 2013-04-25T10:32:55.523 回答
0
看看TTTAttributedLabel,它可以处理文本内的多个链接。
于 2013-04-25T10:29:54.320 回答