UI控件笔记(十六):UI之Uibutton,UIview,UIlbel等初始化的封装

来源:互联网 发布:actionscript 3 源码 编辑:程序博客网 时间:2024/05/18 03:46

一、MyUIClass.h

#import <Foundation/Foundation.h>


@interface MyUIClass : NSObject


+(UIView *)makeUIViewWithFram:(CGRect)rect andBackColor:(UIColor*)color;


+(UILabel *)makeUILabelWithFrame:(CGRect)rect andBackColor:(UIColor*)backColor andText:(NSString *)text andTextColor:(UIColor *)textColor andFont:(UIFont *)font andAlignment:(NSTextAlignment)alignment;


+(UIImageView *)makeUIImageViewWithFrame:(CGRect)rect andImage:(NSString *)imageName;


+(UITextField *)makeUITextFieldWithFrame:(CGRect)rect andDelegate:(id)target andBorderStyle:(UITextBorderStyle)borderStyle andPlaceholder:(NSString *)str  andAutocorrectionType:(UITextAutocorrectionType)autocorrectionType andAutocapitalizationType:(UITextAutocapitalizationType)autocapitalizationType andClearButtonMode:(UITextFieldViewMode)clearButtonMode andSecureTextEntry:(BOOL)secureTextEntry andKeyboardType:(UIKeyboardType)keyboardType andReturnKeyType:(UIReturnKeyType)returnKeyType;


+(UIButton *)makeUIButtonWithFrame:(CGRect)rect andType:(UIButtonType)type andTitle:(NSString *)title andImageName:(NSString *)iamgeName andTarget:(id)target andSelector:(SEL)selector andEvent:(UIControlEvents)event andState:(UIControlState)state;


@end


二、MyUIClass.m

#import "MyUIClass.h"


@implementation MyUIClass


+(UIView *)makeUIViewWithFram:(CGRect)rect andBackColor:(UIColor *)color

{

    UIView *view = [[UIView alloc] initWithFrame:rect];

    view.backgroundColor = color;

    return [view autorelease];

}

+(UILabel *)makeUILabelWithFrame:(CGRect)rect andBackColor:(UIColor *)backColor andText:(NSString *)text andTextColor:(UIColor *)textColor andFont:(UIFont *)font andAlignment:(NSTextAlignment)alignment

{

    UILabel *lab = [[UILabel alloc] initWithFrame:rect];

    lab.text = text;

    lab.backgroundColor = backColor;

    lab.textColor = textColor;

    lab.font = font;

    lab.textAlignment = alignment;

    return [lab autorelease];

    

}


+(UIImageView *)makeUIImageViewWithFrame:(CGRect)rect andImage:(NSString *)imageName

{

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];

    imageView.image = [UIImage imageNamed:imageName];

    return [imageView autorelease];

}

+(UITextField *)makeUITextFieldWithFrame:(CGRect)rect andDelegate:(id)target andBorderStyle:(UITextBorderStyle)borderStyle andPlaceholder:(NSString *)str andAutocorrectionType:(UITextAutocorrectionType)autocorrectionType andAutocapitalizationType:(UITextAutocapitalizationType)autocapitalizationType andClearButtonMode:(UITextFieldViewMode)clearButtonMode andSecureTextEntry:(BOOL)secureTextEntry andKeyboardType:(UIKeyboardType)keyboardType andReturnKeyType:(UIReturnKeyType)returnKeyType

{

    UITextField *textField = [[UITextField alloc] initWithFrame:rect];

    textField.delegate = target;

    textField.borderStyle = borderStyle;

    textField.placeholder = str;

    textField.autocorrectionType =autocorrectionType;

    textField.autocapitalizationType = autocapitalizationType;

    textField.clearButtonMode = clearButtonMode;

    textField.secureTextEntry = secureTextEntry;

    textField.keyboardType = keyboardType;

    textField.returnKeyType = returnKeyType;

    return [textField autorelease];

}

+(UIButton *)makeUIButtonWithFrame:(CGRect)rect andType:(UIButtonType)type andTitle:(NSString *)title andImageName:(NSString *)iamgeName andTarget:(id)target andSelector:(SEL)selector andEvent:(UIControlEvents)event andState:(UIControlState)state

{

    UIButton *btn = [UIButton buttonWithType:type];

    btn.frame = rect;

    if (type ==0) {

        [btn setImage:[UIImage imageNamed:iamgeName] forState:state];

    }else{

        [btn setTitle:title forState:state];

    }

    [btn addTarget:target action:selector forControlEvents:event];

    return btn;

}


@end


0 0