zoukankan      html  css  js  c++  java
  • iphone上一些常用控件代码实现方式(原创)

    本人在开发过程中自己写的控件一般生成代码

    UIkitElements.h

    //
    //  UIkitElements.h
    //  DigitGolf
    //
    //  Created by suruiqang on 8/5/10.
    //  Copyright 2010 __MyCompanyName__. All rights reserved.
    //
    #pragma once
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    
    @interface UIkitElements : NSObject {
    
    }
    +(UIButton*)createButton:(CGRect)rect 
    		 withNormalImage:(NSString*)normalState 
    		   SelectedImage:(NSString*)selectedState 
    				   title:(NSString*)titleStr 
    				 withTag:(NSInteger)tag;
    
    +(UILabel*)createLable:(CGRect)rect 
    			 withTitle:(NSString*)title 
    			titleColor:(UIColor*)color 
    				  Font:(UIFont*)font 
    		 textAlignment:(UITextAlignment)alignmentType;
    
    +(UITextField*)createTextField:(CGRect)rect 
    				   borderStyle:(UITextBorderStyle)borderStyle 
    					   keyType:(UIKeyboardType)keyType
    					   holdStr:(NSString*)holderStr 
    					 returnKey:(UIReturnKeyType)returnType clearButtonMode:(UITextFieldViewMode)mode ;
    
    +(UIProgressView*)createProgressView:(CGRect)rect
    						   viewStyle:(UIProgressViewStyle)style
    					   progressValue:(float)value;
    @end
    
    

    #import "UIkitElements.h"
    
    #define PACKAGE_FILE_PATH(FILE_NAME) [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:FILE_NAME]
    @implementation UIkitElements
    
    #pragma mark -
    #pragma mark *************create a button  *************
    +(UIButton*)createButton:(CGRect)rect
    		 withNormalImage:(NSString*)normalState
    		   SelectedImage:(NSString*)selectedState
    				   title:(NSString*)titleStr
    				 withTag:(NSInteger)tag
    {
    	UIButton* btn = [[UIButton alloc] initWithFrame:rect];
    	[btn setBackgroundImage:[UIImage imageWithContentsOfFile:PACKAGE_FILE_PATH(normalState)] forState:UIControlStateNormal];
    	[btn setBackgroundImage:[UIImage imageWithContentsOfFile:PACKAGE_FILE_PATH(selectedState)] forState:UIControlStateHighlighted];
    [btn addTarget:self action:@selector(btnWasPressed:) forControlEvents:UIControlEventTouchUpInside];
    			btn.showsTouchWhenHighlighted = YES;
    			btn.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleBottomMargin;
    	if(titleStr!=nil)
    	{
    		[btn setTitle:titleStr forState:UIControlStateNormal];
    	}
    	btn.tag = tag;
    	return btn;
    }
    
    #pragma mark -
    #pragma mark *************create a lable  *************
    +(UILabel*)createLable:(CGRect)rect 
    			 withTitle:(NSString*)title 
    			titleColor:(UIColor*)color 
    				  Font:(UIFont*)font 
    		 textAlignment:(UITextAlignment)alignmentType
    {
    	UILabel* lable = [[UILabel alloc] initWithFrame:rect];
    	[lable setText:title];
    	//[lable setTextColor:color];
    	[lable setFont:font];
    	[lable setTextAlignment:alignmentType];
    	lable.backgroundColor = [UIColor clearColor];
    	
    	return lable;
    }
    
    #pragma mark -
    #pragma mark *************create a textfield  *************
    +(UITextField*)createTextField:(CGRect)rect 
    				   borderStyle:(UITextBorderStyle)borderStyle 
    					   keyType:(UIKeyboardType)keyType
    					   holdStr:(NSString*)holderStr 
    					 returnKey:(UIReturnKeyType)returnType clearButtonMode:(UITextFieldViewMode)mode
    {
    	UITextField* textField = [[UITextField alloc] initWithFrame:rect];
    	textField.borderStyle = borderStyle;
    	textField.keyboardType = keyType;
    	textField.placeholder = holderStr;
    	textField.returnKeyType = returnType;
    	textField.clearButtonMode = mode;
    	return textField;
    }
    
    #pragma mark -
    #pragma mark *************create a ProgressView  *************
    +(UIProgressView*)createProgressView:(CGRect)rect
    						   viewStyle:(UIProgressViewStyle)style
    					   progressValue:(float)value
    {
    	UIProgressView* progress = [[UIProgressView alloc] initWithFrame:rect];
    	progress.progressViewStyle = UIProgressViewStyleBar;
    	progress.progress = value;
    	
    	return progress;
    }
    @end
    
    

    以后逐渐补充。。。。

  • 相关阅读:
    openstack 网络架构 nova-network + neutron
    编程算法
    16周(项目四 动态数组)
    iptables惹的祸
    【剑指offer】和为定值的连续正数序列
    root用户改动普通用户文件
    Android学习四、Android中的Adapter
    初探swift语言的学习笔记四(类对象,函数)
    crtmpserver 基本流程分析
    八大排序算法总结
  • 原文地址:https://www.cnblogs.com/moshengren/p/1855247.html
Copyright © 2011-2022 走看看