Thursday, May 30, 2013

UIButton titleColorForState example in Objective C (iOS).

UIButton titleColorForState

Returns the title color used for a state.

- (UIColor *)titleColorForState:(UIControlState)state

Parameters
state
The state that uses the title color. The possible values are described in UIControlState.

Return Value of [UIButton titleColorForState]
The color of the title for the specified state.

UIButton titleColorForState example.
    UIControlState mixedState = UIControlStateSelected | UIControlStateHighlighted;
    [button setImage:[button imageForState:state] forState:state];
    [button setBackgroundImage:[button backgroundImageForState:state] forState:state];
    [button setTitleColor:[button titleColorForState:state] forState:state];

Example of [UIButton titleColorForState].
label.textColor = [button titleColorForState: UIControlStateNormal];

UIButton titleColorForState example.
- (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] autorelease];
}
if ([[cell contentView] viewWithTag:25])
{
    [[[cell contentView] viewWithTag:25] removeFromSuperview];
}


    CustomButton*cButton= [[[self dataSource] otherButtonArr] objectAtIndex:indexPath.row];
    cell.textLabel.text = [cButton titleForState:UIControlStateNormal];
    cell.textLabel.textColor = [cButton titleColorForState:UIControlStateNormal];
    cell.accessoryType =   (cButton.selected)?UITableViewCellAccessoryCheckmark:UITableViewCellAccessoryNone;


  return cell;
  }

  #pragma mark - Table view delegate

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
CustomButton*cButton= [[[self dataSource] otherButtonArr] objectAtIndex:indexPath.row];
[self didSelectedOption:[cButton titleForState:UIControlStateNormal]];
}

End of UIButton titleColorForState example article.