Code for creating custom Label in Xcode?


UILabel *_lblTitle=[[UILabel alloc]initWithFrame:CGRectMake(x,y,w,h)];
    [_lblTitle setText:[[NSString alloc]initWithFormat:@”Add label text here”]];
    [_lblTitle setTextColor:[UIColor redColor]];  // Add your color here.
    [_lblTitle setBackgroundColor:[UIColor grayColor]]; // Add your background color here.
    [_lblTitle setFont:[UIFont systemFontOfSize:15.0]]; // Set your font size here.
    [_lblTitle setNumberOfLines:0];

// Here code for dynamic size length of label.
    _newSizeOfLabel = [_lblTitle.text sizeWithFont:_lblTitle.font
                                 constrainedToSize:_maximumSize  // Defined max size function.
                                     lineBreakMode:_lblTitle.lineBreakMode];
   [cell  addSubview:_lblTitle];

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s