iOS7æ代ã®UITableView
NSAttributedTextã¨Dynamic Typeãå©ç¨ããUITableViewãæ¸ãã¦ã¿ã¾ããã
NSAttributedTextï¼Dynamic Type
XCodeã¨ãåå¹´ã¶ããªã®ã§ãæ£ããã®ããã¾ãèªä¿¡ã¯ãªãã§ãã
ãããªæãã«è¡¨ç¤ºããã¾ããtableViewã®marginãpaddingã¯ããªãé©å½ãªå¤ã§ãã¡ããã¨èª¿ã¹ã¦ã¾ããã
TableViewã®ä½æ³
iOS6ããããããå¤ãã£ã¦ã¾ãããã¤ãã¦ããã奴ã ãã¤ãã¦ãããï¼ãã£ã¦å¢ãã§ããããå¤ããããã¾ããé©åè ã¸ã®éã¯é ãã§ãã
UITableViewCell ã®çæã¨åå©ç¨
iOS5ã¾ã§ã®dequeueReusableCellWithIdentifier:
ã§ã¯ããã£ãã·ã¥ã®Cellãåå¨ããã°åå©ç¨ãããªããã°çæãã¦ãã¾ããããiOS6以éã¯UITableView
ã®æç»ãè¡ãæç¹ã§å¿
è¦ãªCellæ°ãè¨ç®ããäºåã«ãã£ãã·ã¥Cellãä½ãç½®ããã¦ãããã¨ããæ¹æ³ã«å¤ããã¾ããã
ã¾ãviewDidLoad
ã§Cellã®ã¯ã©ã¹ã¨åå©ç¨IDãç»é²ãã¾ãã
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:CellIdentifier];
}
å®éã«Cellãå©ç¨ããã«ã¯ãdequeueReusableCellWithIdentifier:forIndexPath:
ãå¼ã³åºãã¾ãã
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.numberOfLines = 0;
[self _updateCell:cell atIndexPath:indexPath];
return cell;
}
è¦ã¦ã®éããé常ã«ã·ã³ãã«ãªè¨è¿°ã¨ãªããã«ã¹ã¿ã Cellãå©ç¨ãããããªã£ãåé¢ãUITableViewCellStyle
ã®æå®ã¯ä¸å¯è½ã«ãªãã¾ããã
ããªã»ããã®Styleã使ãããå ´åãinitWithStyle:reuseIdentifier:
ãå¼ã³åºãã«ã¹ã¿ã Cellã¯ã©ã¹ãä½ããã¨ããæ®å¿µãªæ¹æ³ãåããã¨ã«ãªãã¾ãã
UITableViewCell ã®é«ãã®è¨ç®
iOS7ã§sizeWithFont
ç³»ã®ã¡ã½ããã¯Deprecatedã¨ãªãã¾ããã
NSString
ãUIè¦ç´ ã«å¯¾ãã¦ãç´æ¥text
ããããã£ã¨ãã¦æ¸¡ãã®ã§ã¯ãªããNSAttributedString
ãattributedText
ããããã£ã¨ãã¦æ¸¡ãããã«ã·ãããã¦ããã®ã§ãããã
NSString
ããè¨ç®ããå ´åã¯boundingRectWithSize:options:attributes:context:
ããNSAttributedString
ããè¨ç®ããå ´åã¯boundingRectWithSize:options:context:
ã使ãããã«å¤ããã¾ããã
AttributedString
NSAttributedString
èªä½ã¯ã¹ã¿ã¤ã«ãNSDictionary
ã¨ãã¦æ¸¡ãã ããªã®ã§ãããã¾ã§é£ããããã§ã¯ãªãã®ã§ãããåé¡ã¯ãã¹ã¿ã¤ã«ãæå®ããNSDictionary
ãã©ãã§çæãããããã§ãã
æåçæã®åº¦ã«è¾æ¸ãçæãã¦ããã¨ãXCode4.3辺ãã§ç°¡æè¨æ³ã追å ãããããã¨ã¯ãããã²ã©ãèªã¿ã«ããã³ã¼ãã«ãªãã¾ããæ¯åè¾æ¸ãçæãããã¨ã«ãªãã®ã§ãããã©ã¼ãã³ã¹ãè¯ããªãã§ãããã
å¾è¿°ããpreferredFontForTextStyle:
æ´æ°ã®é¢ä¿ããã£ã¦ãUIViewController
ã®ããããã£ã¨ãã¦æãããæ¹æ³ãåãã¾ããããå®éã«ã¯ã©ãããæ¹æ³ããããã§ãããâ¦ãAndroidã®Styleãªã½ã¼ã¹ã¿ãããªç°¡åãªæ¹æ³ã¯ãªããã§ããâ¦ã
Dyanmic Type
iOS7ããè¨å®ã«ãã©ã³ãã®å¤§ãããè¨å®ããæ©è½ã追å ããã¾ããã
ããã¯Text Kitã®æ©è½ã®ä¸ã¤ã§ãã
Text Kitã¨ã¯
ããã¾ã§Core Textãç´æ¥å©ããããããã¯UIWebView
ã使ã£ã¦æç»ããªããã°å®ç¾ã§ããªãã£ããªãããªããã¹ã表ç¾ï¼å±æ§ããã¹ããåçãµã¤ãºå¤æ´ãã«ã¼ãã³ã°çï¼ããä»å¾ã¯UILabel
ãUITextView
ã§å®ç¾ã§ããããã«ããããã«ç¨æããããä¸éãã¬ã¼ã ã¯ã¼ã¯ç¾¤ã§ãã
iOS7以éã®ãããã«ãã¶ã¤ã³ã§ã¯ããªãã¸ã§ã¯ããã¡ã¿ãã¡ãããããã¹ããéè¦ãªã®ã§åãå ¥ãã¦ããã¨ãããã¨ã§ãããã
åçãªããã¹ãã¬ã¤ã¢ã¦ããå¯è½ã«ããããã®ã¯ã©ã¹ãªã©ã追å ããã¦ããã¿ããã§ãã
Dynamic Type ã®æ©è½ã¨å®è£
Dynamic Typeã«é¢ãã¦ãOSã¨ãã¦ãµãã¼ããã¦ããããã¨ã¯æ¬¡ã®äºã¤ã ãã§ãã
UIFontDescriptor
ã¤ã³ã¹ã¿ã³ã¹ãçæããéã«ãã¦ã¼ã¶ã¼ã®ãã©ã³ããµã¤ãºæå®ãåæ ãããã- ã¦ã¼ã¶ã¼ããã©ã³ããµã¤ãºæå®ãå¤æ´ããéã«ãNotificationãçºè¡ãããï¼å®éã«ã¯ã¢ããªãåã³ãã©ã¢ã°ã©ã°ã³ãã«ãªã£ãç¬éã«éç¥ãæ¥ãï¼
ãã£ãäºã¤ã ãã§ãâ¦ã
Dynamic Typeãå©ç¨ããããã«ã¯ãUIFont
ã®åå¾ã«preferredFontForTextStyle:
ãããã¯ãfontWithDescriptor:
ã使ãå¿
è¦ãããã¾ãã
TextStyleã¨ãã¦æ¸¡ãã®ã¯NSString
ã§ãWithDescriptorã¨ãã¦æ¸¡ãã®ã¯UIFontDescriptor
ã§ãããåè
ã®æååã¯UIFontDescriptor
ã®å®æ°ã§ãããDynamic Typeç解ã®éµã¨ãªãã®ã¯UIFontDescriptor
ã¯ã©ã¹ã§ãã
Class Referenceã¯æãèªã¿ãããã¦ããªãããã©ããã®ãã©ã³ããã©ãæç»ãããã®ããã¾ãUIFontDescriptor
ã§å®ç¾©ããDescriptorããUIFont
ãçæãããã¨ããäºæéãå¿
è¦ã«ãªã£ãâ¦ã¨ç解ãã¦ããã°ãããããåé¡ãªãã¨æãã¾ãã
å®éã«ã¯FontDescriptor
ãç´æ¥çæãããã¨ã¯ç¨ã§ãUIFontTextStyleHeadline
ãªã©ã®ããªã»ãããããã¹ã¿ã¤ã«ããpreferredFontForTextStyle:
ã§æ¸¡ããã¨ã«ãªãã®ã§ãããã
ã¦ã¼ã¶ã¼ãè¨å®ãããã©ã³ããµã¤ãºã®å¤æ´ãè¡ã£ãå ´åãUIContentSizeCategoryDidChangeNotification
ã®éç¥ãçºè¡ãããã®ã§ãããæ¬å½ã«éç¥ãçºè¡ãããã ããªã®ã§ããããåãåã£ã¦åã¬ã¤ã¢ã¦ããè¡ãã®ã¯éçºè
ã®ç¾©åã§ãã
Dynamic Type æ´æ°ã®ãã¤ã³ã
éè¦ãªã®ã¯ãUIFont
㯠ä¸å¤ã¯ã©ã¹ ã¨ãããã¨ã§ãã
ãã®ãããã¦ã¼ã¶ã¼ãè¨å®ã§ãã©ã³ããµã¤ãºã®å¤æ´ãè¡ã£ãå ´åãpreferredFontForTextStyle:
ã§UIFont
ãåçæããå¿
è¦ãããã®ã§ãã
/**
ãã©ã³ããµã¤ãºå¤æ´ã®éç¥ãåãåã£ãéã«ã
ãã©ã³ãå±æ§ãæ´æ°ããä¸ã§ããã¼ãã«ãåæç»ãã
*/
- (void)preferredContentSizeChanged:(NSNotification *)aNotification {
[self _refreshFontAttributes];
[self.tableView reloadData];
}
/**
ãã©ã³ãå±æ§ãæ´æ°ãã
*/
- (void)_refreshFontAttributes
{
self.bodyAttribute = @{NSFontAttributeName : [UIFont preferredFontForTextStyle:UIFontTextStyleBody]};
self.subTitleAttribute = @{NSFontAttributeName : [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline],
NSForegroundColorAttributeName : [UIColor darkGrayColor]};
}
éç¥ãåãåã£ãããUITableView
ãåæç»ããåã«ãã©ã³ãå±æ§ãæ´æ°ããUIViewController
ã®ããããã£ã¨ãã¦ä¿æããææ³ãã¨ã£ã¦ãã¾ãã
ä¸åº¦ã ãUIFontDescriptor
ããUIFont
ãçæããåå¾ããè¾æ¸ãæç»ãCellã®é«ãã®è¨ç®ã«ä½¿ãã¾ãããã¨ã§ãUITableView
å
ã§ã®ãªãã¸ã§ã¯ãçæåæ°ãæå°éã¨ããããã§ãã
å®æ°å®ç¾©ããã¦ãããã®ã«ã¤ãã¦ã¯ãçæã³ã¹ããæ°ã«ããå¿ è¦ãããã¨ãæããªãã®ã§ãã©ã®ç¨åº¦ããã©ã¼ãã³ã¹å¤ããã®ãã¯åããã¾ãããâ¦ã