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

一、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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值