2014-12-31 5 views

답변

0

당신이하는 .m 파일에서 .H 파일

// 
// UILabel+withString.h 
// 

#import <Foundation/Foundation.h> 

@interface UILabel (withString) 

+ (UILabel *)labelWithString:(NSString *)string 
        font:(UIFont *)font 
        color:(UIColor *)color 
       container:(CGRect)container 
        origin:(CGPoint)origin; 

@end 

에 대한 분류 클래스를 만들 수 있습니다

// 
// UILabel+withString.m 
// 

#import "UILabel+withString.h" 


@implementation UILabel (withString) 

+ (UILabel *)labelWithString:(NSString *)string 
        font:(UIFont *)font 
        color:(UIColor *)color 
       container:(CGRect)container 
        origin:(CGPoint)origin { 
CGSize size = [string sizeWithFont:font constrainedToSize:container.size 
    lineBreakMode:UILineBreakModeTailTruncation]; 

UILabel *label = [[[UILabel alloc] 
    initWithFrame:CGRectMake(origin.x, origin.y, container.size.width, size.height)] autorelease]; 
label.text = string; 
label.font = font; 
label.textColor = color; 
label.textAlignment = UITextAlignmentLeft; 
label.numberOfLines = 1; 
label.lineBreakMode = UILineBreakModeTailTruncation; 
    label.backgroundColor = [UIColor clearColor]; 

return label; 
} 

@end 

다음 뷰 컨트롤러에이

+0

이 방법으로 호출 할 수 있습니다 내 레이블이 다른 ViewController에 나타 납니까? – user3376632

+0

그냥이 파일 –

+0

을 가져와야합니다. 어떻게 내 View Controller에서 호출 할 수 있습니까? – user3376632

관련 문제