Objective-c:以编程方式设计UIView / UILabel

时间:2016-05-25 05:42:15

标签: ios objective-c uiview uilabel

我想在目标c 中以编程方式设计UIView / UILabel这样的图像。特别是中间的边缘。有人可以帮忙吗?

enter image description here

目前我有:

UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.tabPosition.x,self.tabPosition.y,120,20)]; //or whatever size you need
            myLabel.center = self.tabPosition;
            [myLabel setFont:[UIFont systemFontOfSize:12]];
            myLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6f];
            myLabel.textColor = [UIColor whiteColor];
            myLabel.textAlignment = NSTextAlignmentCenter;
            myLabel.text = [NSString stringWithFormat:@"%@  %@",data.user.firstName,data.user.lastName] ;
            myLabel.tag = indexPath.row;
            myLabel.userInteractionEnabled = YES;

            UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc]
                                               initWithTarget:self
                                               action:@selector(labelDragged:)] ;
            [myLabel addGestureRecognizer:gesture];


            [self.picture addSubview:myLabel];

哪位给我:
enter image description here

2 个答案:

答案 0 :(得分:0)

你需要一个像你一样的小图像。

设置UIImageview的拉伸属性,使其按您设置文本大小和边缘将保持在中间(refer this link

答案 1 :(得分:0)

已有很多答案,请选择适合您的答案:

basic and simplest

arrow and round corner

creative solution

希望这些能帮助你!!