I want to achieve something like this inside a UIView:
I have created a custom UILabel with a custom init method:
@implementation TagLabel
- (id)init {
self = [super initWithFrame:CGRectMake(0, 0, 100, 40)];
if (self) {
self.layer.borderColor = [UIColor whiteColor].CGColor;
self.layer.borderWidth = 4.0;
self.layer.cornerRadius = 4;
self.backgroundColor = [UIColor greenColor];
self.textColor = [UIColor whiteColor];
self.textAlignment = UITextAlignmentCenter;
}
return self;
}
@end
And I create and add each label to the view like so:
for (NSDictionary *tag in [self.voicenote objectForKey:@"Tag"]) {
TagLabel *tagLabel = [[TagLabel alloc] init];
tagLabel.text = [tag objectForKey:@"tag"];
[self.tagsView addSubview:tagLabel];
}
Yet all I get is a blank UIView, am I missing something? Would there be a better way to achieve this?
EDIT: one problem solved, modified the UILabel code to set the background color directly to the background, and now they show, now how can I make them be one beside the other and not overlapped?