iOS7ã®ãã¿ã³ãæ§Round Rect Buttonã®ããã«ãã
iOS 6.1ããããã¯ãã以åã«ä½ãããã¢ããªã«ããããã¿ã³ã¨ã¯ãRound Rect Buttonã¨ããè§ä¸¸ã®ãã¿ã³ãããã©ã«ãã§ãã£ããã¾ããããèªä½ã決ãã¦è¯ãè¦ãç®ã§ã¯ãªãã£ãã®ã§ãå¤ãã®å ´åã¯ã«ã¹ã¿ã ãã¿ã³ãä½æãã¦ããããã ããä¸ã«ã¯Round Rectã使ã£ã¦ããã¢ããªãããã ããã
ãããã£ãã¢ããªãiOS7ç¨ã«Xcode 5.0ã§åã³ã³ãã¤ã«ããã¨ããã¿ã³ã®å¤è¦³ã¯ããµã¡ãªããèæ¯è²ãªãã®ãããããã¿ã³ã«ã¯è¦ããªãè¦ãç®ã«å¤ãã£ã¦ãã¾ãã
ãããå ã®Round Rectã®ãããªè¦ãç®ã«å¤æ´ããã«ã¯ãViewController#viewDidLoadãªã©ã§ã以ä¸ã®ããã«ãã¦ããã
button.layer.borderColor = [UIColor grayColor].CGColor; button.layer.borderWidth = 1.0f; button.layer.cornerRadius = 7.5f;
ããããæ°å¤ãã®ç»é¢ãæã¤ã¢ããªã§ãã®å¯¾å¦ãããã®ã¯å°ã 骨ãæãããä»®ã«ããã¹ã¦ã®Round Rectãã¿ã³ããStoryboardä¸ã§å®ç¾©ããã¦ããã¨ãããªãã°ããã¹ã¦ã®ãã¿ã³ã§å ±éã®å¤è¦³è¨å®ãè¡ãã«ã¹ã¿ã ãã¿ã³ã¯ã©ã¹Cãå®ç¾©ããä¸ã§ãStoryboardã®åãã¿ã³ã®å®è£ ã¯ã©ã¹ãCã«è¨å®ãã¦ããã°ããããã®ããã«ããã°ãStoryboard以å¤ã®ã½ã¼ã¹ãã¡ã¤ã«ã¯ä¸åå¤æ´ãããã¨ãªã対å¦ã§ããã¯ãã ã
MyButton.h
#import <UIKit/UIKit.h> @interface MyButton : UIButton @end
MyButton.m
#import "MyButton.h" @implementation MyButton -(id)initWithCoder:(NSCoder*)aDecoder { self = [super initWithCoder:aDecoder]; if (self) { self.layer.borderColor = [UIColor grayColor].CGColor; self.layer.borderWidth = 1.0f; self.layer.cornerRadius = 7.5f; } return self; } @end
ãã¶ããããä¸çªç°¡åãªå¯¾å¿æ¹æ³ã§ã¯ãªãã ãããã
ã¨ããã§ãããå³å¯ã«Round Rectã®ããã«ããã«ã¯ããã¿ã³ãæ¼ãããã¨ãã«èæ¯ãéãã¿ã¤ãã«ããã¹ããç½ã«ãã¦ããå¿ è¦ãããã®ã ããUIButton#setBackgroundColor:forState:ã¡ã½ããã¨ããã®ãè¦å½ãããªããããã¾ã§ããã«ã¯ãtouchDownInsideãªã©ã®ã¤ãã³ãã§èæ¯è²ãªã©ãå¤ãã¦ãtouchDragOutside, touchUpInside, touchUpOutsideãªã©ã§å ã«æ»ãã¦ãããªããã°ãªããªãã®ã ãããã