2016年1月28日

2680 ワード

一、事前にコントロールスタイルをカスタマイズする.構造関数を書き換えるのと同じで、例えばUIButton、枠線付きbuttonが必要であれば、YDgridButton@implement-(vioid)drawRect:(CGRect)rect{//カスタムスタイルを設定する}@endをカスタマイズすることができる.
呼び出し時にbuttonのstyleをcustomと指定し、buttonをYDgridButtonと指定するとbuttonのスタイルは枠線付きです
二、controlとxibの関連付け説明の便宜上、customControlとcustomXib 2.1、controlをxibと指定するfile owner 2.2、viewをfile Owner 2.3に関連付ける、controlの初期化関数でinitWithNib-(instanceType)init{if(self=[[super alloc]initWithNib:@]customXib"option:nil]){return self;}
三、コントロールを動的に追加する際の注意点怠惰なロードでコントロールを動的に追加する場合は、コントロールをstrongタイプ@property(nonatomic,strong)UIButton*buttonと書く.
  viewDidLoad , weak 
@property (nonatomic,weak) UIButton *button;
-(void)viewDidLoad
{
UIButton *button = [[UIButton alloc]init];
[self.view addSubView:button];
_button = button;
[super viewDidLoad];
}

四、appDelegateにルートコントローラを手動でロード説明の便宜上、ルートビューはcustomRootView 4.1まずルートwindow UIWindow*window=[[UIAPplication shareApplication]rootWindow];//ルートビューcustomRootView*customRootView=[[customRootView alloc]init];//このvivigationでこのview UINAvigation*nav=[[UINAvigation alloc]initWithRootControl:customRootView];//次にnavをルートビューwindowとして指定する.rootViewControl = nav; 4.2はありません
五、handlerについての感想は、最も純粋なビジネス層であり、ユーザーのインタラクションにもページレイアウトにも関与しない.独立して層を抜くべきだ.書くときはbaseHandlerがあるはずです
typedef void(^completionBlock)(id obj) ; typedef void(^successBlock)(id obj) ; typedef void(^FailedBlock)(id obj) ;
@interface BaseHandler:NSObject
@end
具体的なビジネスhandlerクラスはこのbaseクラスを継承します
MonitorHandlerクラス
@interface MonitorHandler:BaseHandler
-(void)executeMonitorWithParam:(customEntity *)entity success:( SuccessBlock )success fail:(FailBlock)fail;
@end
六、xibからcellをロードする方法static NSString*CellIdentifiier=@"Cell";//xibファイルの名前を書くCell cell=(Cell)[tableViewdequeueReusableCellWithIdentifiier:CellIdentifier];//多重化可能なcell if(!cell){cell=[[NSBundle mainBundle]loadNibName:NSStringFromClass([Cell class])owner:self options:nil]objectAtIndex:0];return cell; *まとめ:NSBundle mainBundleはリソースファイルをロードするために使用され、xibもリソースなので、このようにロードすることもできます.
一、buttonスタイル設定1.1お気に入りの背景画像を選択1.2 resizableImageWithCapInsetsメソッドUIImge*buttonImage=[[UIImage imageName:@]orangeButton.png]]resizableImageWithCapInsets:UIEdgeInsetsMake(18,18,18,18,18)];UIImage *buttonImageHighlight = [[UIImage imageNamed:@”orangeButtonHighlight.png”] resizableImageWithCapInsets:UIEdgeInsetsMake(18, 18, 18, 18)];
//Set the background for any states you plan to use [saveButton setBackgroundImage:buttonImage forState:UIControlStateNormal]; [saveButton setBackgroundImage:buttonImageHighlight forState:UIControlStateHighlighted];
簡単です.ここでは、新しい画像を作成することなく、ボタンのサイズを変更することができます.`