The code below shows how to:
- Create new UILabel
- Set UILabel position (x,y) to center and size
- Set UILabel font alignment, color, font name and size
- Add UILabel to your View
- Populate UILabel with an NSString for text.
UILabel *scoreLabel = [ [UILabel alloc ] initWithFrame:CGRectMake((self.bounds.size.width / 2), 0.0, 150.0, 43.0) ]; scoreLabel.textAlignment = UITextAlignmentCenter; scoreLabel.textColor = [UIColor whiteColor]; scoreLabel.backgroundColor = [UIColor blackColor]; scoreLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(36.0)]; [self addSubview:scoreLabel]; scoreLabel.text = [NSString stringWithFormat: @"%d", score];
If you’ve got a better, more efficient way of doing the above, please feel free to comment.
No comments:
Post a Comment