Objective-c : 以编程方式设计 UIView/UILabel
Objective-c : Designing UIView/UILabel Programmatically
我想在 objective c 中以编程方式设计一个像这张图片的 UIView
/UILabel
。特别是中间的边缘。有人可以帮忙吗?
目前我有:
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];
哪个给我:
您需要一张像您提供的样品一样的小图片。
设置 UIImageview 的拉伸 属性,这样它就会根据您的设置进行设置 文本大小和边缘将保持在中间 (refer this link)
已有很多答案,选择适合您的答案:
basic and simplest
希望这些对你有所帮助!!
我想在 objective c 中以编程方式设计一个像这张图片的 UIView
/UILabel
。特别是中间的边缘。有人可以帮忙吗?
目前我有:
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];
哪个给我:
您需要一张像您提供的样品一样的小图片。
设置 UIImageview 的拉伸 属性,这样它就会根据您的设置进行设置 文本大小和边缘将保持在中间 (refer this link)
已有很多答案,选择适合您的答案:
basic and simplest
希望这些对你有所帮助!!