概述
.h
#import <UIKit/UIKit.h>
@interface DetailLable : UILabel
-(void)setText:(NSString *)titleText title:(NSString *)text setFram:(CGRect)frame;
@end
.m
#import "DetailLable.h"
#define cellpading 8
@implementation DetailLable
-(void)setText:(NSString *)titleText title:(NSString *)text setFram:(CGRect)frame
{
self.textColor = [UIColor blackColor];
self.font = [UIFont fontWithName: @"Helvetica-Bold" size : 17.0 ];
float sizex = frame.origin.x;
float sizey = frame.origin.y;
NSString *theText =
[titleText stringByAppendingFormat:@"%@",text];;
CGSize theStringSize = [theText sizeWithFont:self.font
constrainedToSize:self.frame.size
lineBreakMode:self.lineBreakMode];
//Adjust the size of the UILable
self.frame = CGRectMake(sizex,
sizey+cellpading,
theStringSize.width, theStringSize.height);
self.text = theText;
}
实现
DetailLable *imageStyleMuchNow = [[DetailLable alloc] init];
[imageStyleMuchNow setText:@"899.0" title:@"元" setFram:CGRectMake(10, imageView.frame.origin.y+imageView.frame.size.height,40,20)];
imageStyleMuchNow.textColor = [UIColor blueColor];
[scrollView addSubview:imageStyleMuchNow];
最后
以上就是无奈芹菜为你收集整理的自定义Lable设置Lable与文字长度,两个字符串拼接的全部内容,希望文章能够帮你解决自定义Lable设置Lable与文字长度,两个字符串拼接所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复