.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];
版权声明:本文为u010469726原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。