I have a UIButton
subclass which contains a UITextView
and two UILabels
I create them doing the following:
UILabel *authorName = [[UILabel alloc] initWithFrame: CGRectMake(0, viewHeight, viewWidth, 16)];
authorName.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.5];
authorName.textColor = [UIColor whiteColor];
authorName.font = [UIFont systemFontOfSize:13];
authorName.text = [NSString stringWithFormat:@"@%@",[data objectForKey:@"username"]];
[self addSubview:authorName];
UILabel *likes = [[UILabel alloc] initWithFrame:CGRectMake(viewWidth-50, viewHeight-20, 50, 20)];
likes.backgroundColor = authorName.backgroundColor;
likes.textColor = authorName.textColor;
likes.textAlignment = NSTextAlignmentCenter;
likes.font = authorName.font;
likes.text = [NSString stringWithFormat:@"Likes: %@", [data objectForKey:@"likes"]];
[self addSubview:likes];
UITextView *postText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, viewWidth, viewHeight)];
postText.editable = NO;
postText.text = [NSString stringWithFormat:@"%@",[data objectForKey:@"text"]];
postText.font = [UIFont systemFontOfSize:16];
postText.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:0.6];
The problem is with the last one postText
which uses the frame
of the subclass UIButton
, I want to use that button, by adding this postText
to the bottom of subviews
, because if it's on the top I will not be able to tap on the button.
I tried to use
[self bringSubviewToFront:self];
And
[self sendSubviewToBack:postText];
And
[self insertSubview:postText aboveSubview:authorName];
And, finally
[self insertSubview:postText atIndex:0];
But none of them work for some reason.