在我的应用中,
我正在按一个按钮
并在其上添加红色标签作为子视图。
但按钮的边框在边框上重叠,请看图像。
这是我的代码。
类别表示绿色框状按钮
红色框是 UILabel
我想我
Category *category=[[Category alloc] initWithName:[dict valueForKey:@"category_name"] identity:[[dict valueForKey:@"category_id"] intValue] imageName:nil];
//Button Formatting.
[category setBackgroundColor:[UIColor colorWithRed:126.0/255.0 green:187.0/255.0 blue:75.0/255.0 alpha:1.0]];
[[category layer] setBorderWidth:3.0];
[[category layer] setBorderColor:[[UIColor grayColor] CGColor]];
/*Label Formatting.*/
category.lblimagesCount=[[UILabel alloc] initWithFrame:CGRectMake(category.frame.size.width-22, category.frame.origin.y-18, 26, 26)];
[category.lblimagesCount setBackgroundColor:[UIColor redColor]];
[[category.lblimagesCount layer] setBorderWidth:2.0];
[[category.lblimagesCount layer] setBorderColor:[[UIColor whiteColor] CGColor]];
[category.lblimagesCount setFont:[UIFont boldSystemFontOfSize:18]];
[category.lblimagesCount setTextColor:[UIColor whiteColor]];
[[category.lblimagesCount layer] setOpacity:1.0];
[category.lblimagesCount setTextAlignment:UITextAlignmentCenter];
[category addSubview:category.lblimagesCount];
[self.viewHeader addSubview:category];
答案 0 :(得分:1)
category.lblimagesCount.center=CGPointMake(category.frame.origin.x+category.frame.size.width, category.frame.origin.y);
添加此内容并在上一次添加此
[self.viewHeader addSubview:category];
[self.viewHeader addSubview:category.lblimagesCount];
答案 1 :(得分:0)
如果你想让redLabel不重叠类别,那么根据“self.view.bounds”这个设置它的Frame,并在类别/ Self
上设置addSubView答案 2 :(得分:0)
尝试
[self.viewHeader bringSubviewToFront:category];
添加为子视图后