SlideShare una empresa de Scribd logo
1 de 8
Descargar para leer sin conexión
最近ViewControllerを
どんな風に書いているか
@u16suzu
http://u16suzu.hatenablog.com/
自己紹介
• @u16suzu
• iOSを仕事で初めて1年と2ヶ月くらい
• Railsもやります. プログラミング大好き!
今日の内容
• xib, story boardを使わないでコードだけで iOSを
書くときに,どういう風にViewControllerをかいて
いるか
• 主にビューの描画部分について
- (void)viewDidLoad{
[super viewDidLoad];
!
UIButton*btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(100, 100, 100, 50);
[btn setTitle:@"Button" forState:UIControlStateNormal];
[btn sizeToFit];
[self.view addSubview:btn];
UILabel*l = [[UILabel alloc]initWithFrame:CGRectMake(100, 150, 100, 50)];
l.text = @"label";
[self.view addSubview:l];
}
昔
viewDidLoad にコントロールの初期化と位置指定
のコードが全て書いてある
今
コントロールの初期化と位置指定を分けている
@interface ViewController ()
@property (nonatomic) UIView*titleView;
@property (nonatomic) CustomView*customView;
@end
!
@implementation ViewController
- (void)loadView{
[super loadView];
[self.view addSubview:self.titleView];
[self.view addSubview:self.customView];
}
!
- (void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
CGRect titleViewFrame = CGRectMake(50, 50, 50, 50);
self.titleView.frame = titleViewFrame;
CGRect customViewFrame = CGRectMake(50, 100, 300, 100);
self.customView.frame = customViewFrame;
}
!
#pragma mark - Views
!
- (UIView*)titleView{
if(!_titleView){
_titleView = [UIView new];
_titleView.backgroundColor = [UIColor redColor];
}
return _titleView;
}
!
- (CustomView*)customView{
if(!_customView){
_customView = [CustomView new];
}
return _customView;
}
!
@end
プロパティで宣言
アクセッサで初期化
viewDidLayoutSubviews
で位置指定
loadViewでaddSubview
改善ポイント
• コントロールの位置の変更が容易
• ソースコードが読みやすくなった
• カスタムビューに分割しやすい
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self addSubview:self.firstButton];
}
return self;
}
!
#pragma - Views
!
- (void)layoutSubviews{
[super layoutSubviews];
[self.firstButton sizeToFit];
CGRect frame = CGRectMake(0, 0, 60, 30);
self.firstButton.frame = frame;
}
!
- (UIButton*)firstButton{
if(!_firstButton){
_firstButton = [UIButton buttonWithType:UIButtonTypeSystem];
[_firstButton setTitle:@"firstButton" forState:UIControlStateNormal];
}
return _firstButton;
}
今のカスタムビュー
layoutSubviewsで位置指定
initWithFrameで addSubview
あとは VCと同じ
以上です!

Más contenido relacionado

La actualidad más candente

Excel 方眼紙撲滅委員会 活動報告 2012.11 #odstudy
Excel 方眼紙撲滅委員会 活動報告 2012.11 #odstudyExcel 方眼紙撲滅委員会 活動報告 2012.11 #odstudy
Excel 方眼紙撲滅委員会 活動報告 2012.11 #odstudy
Takeshi Komiya
 

La actualidad más candente (12)

Enhancements with 3D Touch
Enhancements with 3D TouchEnhancements with 3D Touch
Enhancements with 3D Touch
 
絶望しない! コミケ
絶望しない! コミケ絶望しない! コミケ
絶望しない! コミケ
 
jQueryで気をつけてほしいこと
jQueryで気をつけてほしいことjQueryで気をつけてほしいこと
jQueryで気をつけてほしいこと
 
Jsのビルド環境
Jsのビルド環境Jsのビルド環境
Jsのビルド環境
 
Study Intro Backbone
Study Intro BackboneStudy Intro Backbone
Study Intro Backbone
 
Apple watch対応アプリのポイントや基本実装・連携tips
Apple watch対応アプリのポイントや基本実装・連携tipsApple watch対応アプリのポイントや基本実装・連携tips
Apple watch対応アプリのポイントや基本実装・連携tips
 
Effective flutter
Effective flutterEffective flutter
Effective flutter
 
Alt01-LT
Alt01-LTAlt01-LT
Alt01-LT
 
YUI
YUIYUI
YUI
 
JavaScriptと共に歩いて行く決意をした君へ
JavaScriptと共に歩いて行く決意をした君へJavaScriptと共に歩いて行く決意をした君へ
JavaScriptと共に歩いて行く決意をした君へ
 
SQLアンチパターン読書会 15章 ランダムセレクション 説明資料
SQLアンチパターン読書会 15章 ランダムセレクション 説明資料SQLアンチパターン読書会 15章 ランダムセレクション 説明資料
SQLアンチパターン読書会 15章 ランダムセレクション 説明資料
 
Excel 方眼紙撲滅委員会 活動報告 2012.11 #odstudy
Excel 方眼紙撲滅委員会 活動報告 2012.11 #odstudyExcel 方眼紙撲滅委員会 活動報告 2012.11 #odstudy
Excel 方眼紙撲滅委員会 活動報告 2012.11 #odstudy
 

Destacado

Wellington Residences - Lisa
Wellington Residences - LisaWellington Residences - Lisa
Wellington Residences - Lisa
nikatherez
 
Paper María Iglesia - CEIB: A R&D services in bioimaging oriented to integrat...
Paper María Iglesia - CEIB: A R&D services in bioimaging oriented to integrat...Paper María Iglesia - CEIB: A R&D services in bioimaging oriented to integrat...
Paper María Iglesia - CEIB: A R&D services in bioimaging oriented to integrat...
WTHS
 
Paper Florencio Cano - Patient data security in a wireless and mobile world
Paper Florencio Cano - Patient data security in a wireless and mobile worldPaper Florencio Cano - Patient data security in a wireless and mobile world
Paper Florencio Cano - Patient data security in a wireless and mobile world
WTHS
 
The Maori :background
The Maori :backgroundThe Maori :background
The Maori :background
MRINCON002
 
عامر عرموش
عامر عرموشعامر عرموش
عامر عرموش
Amer Armoush
 
Basic html
Basic htmlBasic html
Basic html
dand_01
 
Audience research
Audience researchAudience research
Audience research
sherieallen
 
Question 2 - Evaluation
Question 2 - EvaluationQuestion 2 - Evaluation
Question 2 - Evaluation
FayBurmingham
 
New Year’s Eve in New York City
New Year’s Eve in New York CityNew Year’s Eve in New York City
New Year’s Eve in New York City
rogerfranquesa
 

Destacado (20)

Alvaro Fides - Use of hierarchical model-view-controller architecture for use...
Alvaro Fides - Use of hierarchical model-view-controller architecture for use...Alvaro Fides - Use of hierarchical model-view-controller architecture for use...
Alvaro Fides - Use of hierarchical model-view-controller architecture for use...
 
Wellington Residences - Lisa
Wellington Residences - LisaWellington Residences - Lisa
Wellington Residences - Lisa
 
Paper María Iglesia - CEIB: A R&D services in bioimaging oriented to integrat...
Paper María Iglesia - CEIB: A R&D services in bioimaging oriented to integrat...Paper María Iglesia - CEIB: A R&D services in bioimaging oriented to integrat...
Paper María Iglesia - CEIB: A R&D services in bioimaging oriented to integrat...
 
Registry of Course Trainers For 2013
Registry of Course Trainers For 2013Registry of Course Trainers For 2013
Registry of Course Trainers For 2013
 
Paper Florencio Cano - Patient data security in a wireless and mobile world
Paper Florencio Cano - Patient data security in a wireless and mobile worldPaper Florencio Cano - Patient data security in a wireless and mobile world
Paper Florencio Cano - Patient data security in a wireless and mobile world
 
The Maori :background
The Maori :backgroundThe Maori :background
The Maori :background
 
Beni Gómez - APTIC a knowledge repository for parents and caregivers of chil...
Beni Gómez  - APTIC a knowledge repository for parents and caregivers of chil...Beni Gómez  - APTIC a knowledge repository for parents and caregivers of chil...
Beni Gómez - APTIC a knowledge repository for parents and caregivers of chil...
 
عامر عرموش
عامر عرموشعامر عرموش
عامر عرموش
 
Basic html
Basic htmlBasic html
Basic html
 
Alejandro Gonzalez - An iPhone-based application for promoting type 2 diabeti...
Alejandro Gonzalez - An iPhone-based application for promoting type 2 diabeti...Alejandro Gonzalez - An iPhone-based application for promoting type 2 diabeti...
Alejandro Gonzalez - An iPhone-based application for promoting type 2 diabeti...
 
Presentation finale3 sfr2011
Presentation finale3 sfr2011Presentation finale3 sfr2011
Presentation finale3 sfr2011
 
Audience research
Audience researchAudience research
Audience research
 
Mercedes Serrano - Guía metabólica: empowerment through health 2.0 tools in ...
Mercedes Serrano -  Guía metabólica: empowerment through health 2.0 tools in ...Mercedes Serrano -  Guía metabólica: empowerment through health 2.0 tools in ...
Mercedes Serrano - Guía metabólica: empowerment through health 2.0 tools in ...
 
Chapter13
Chapter13Chapter13
Chapter13
 
Cintai pangan lokal
Cintai pangan lokalCintai pangan lokal
Cintai pangan lokal
 
Question 2 - Evaluation
Question 2 - EvaluationQuestion 2 - Evaluation
Question 2 - Evaluation
 
Manuel Armañones - Mesa redonda: Health 2.0
Manuel Armañones -  Mesa redonda:  Health 2.0Manuel Armañones -  Mesa redonda:  Health 2.0
Manuel Armañones - Mesa redonda: Health 2.0
 
New Year’s Eve in New York City
New Year’s Eve in New York CityNew Year’s Eve in New York City
New Year’s Eve in New York City
 
Buildings by jihad awad
Buildings by jihad awadBuildings by jihad awad
Buildings by jihad awad
 
Professional Innovator Development
Professional Innovator DevelopmentProfessional Innovator Development
Professional Innovator Development
 

Similar a よこへな3 15発表資料 最近ViewController をどんな感じで書いているか

20121201yidev hirobe iPad miniでRetina
20121201yidev hirobe iPad miniでRetina20121201yidev hirobe iPad miniでRetina
20121201yidev hirobe iPad miniでRetina
Kazuya Hirobe
 
Css nite(2010.09.23)
Css nite(2010.09.23)Css nite(2010.09.23)
Css nite(2010.09.23)
Yoshiki Ushida
 

Similar a よこへな3 15発表資料 最近ViewController をどんな感じで書いているか (20)

20121201yidev hirobe iPad miniでRetina
20121201yidev hirobe iPad miniでRetina20121201yidev hirobe iPad miniでRetina
20121201yidev hirobe iPad miniでRetina
 
iOS 9 Bootcamp #6 UIKit
iOS 9 Bootcamp #6 UIKitiOS 9 Bootcamp #6 UIKit
iOS 9 Bootcamp #6 UIKit
 
BaseViewControllerは作りたくない
BaseViewControllerは作りたくないBaseViewControllerは作りたくない
BaseViewControllerは作りたくない
 
UI要素を動的に利用する
UI要素を動的に利用するUI要素を動的に利用する
UI要素を動的に利用する
 
2012 05-19第44回cocoa勉強会発表資料
2012 05-19第44回cocoa勉強会発表資料2012 05-19第44回cocoa勉強会発表資料
2012 05-19第44回cocoa勉強会発表資料
 
RxDataSourceをNSDiffableDataSourceへ置き換える際のTips集紹介
RxDataSourceをNSDiffableDataSourceへ置き換える際のTips集紹介RxDataSourceをNSDiffableDataSourceへ置き換える際のTips集紹介
RxDataSourceをNSDiffableDataSourceへ置き換える際のTips集紹介
 
試して感覚を掴んでみるUICollectionViewCompositionalLayout & Combine
試して感覚を掴んでみるUICollectionViewCompositionalLayout & Combine試して感覚を掴んでみるUICollectionViewCompositionalLayout & Combine
試して感覚を掴んでみるUICollectionViewCompositionalLayout & Combine
 
Css nite(2010.09.23)
Css nite(2010.09.23)Css nite(2010.09.23)
Css nite(2010.09.23)
 
Introduction for Browser Side MVC
Introduction for Browser Side MVCIntroduction for Browser Side MVC
Introduction for Browser Side MVC
 
iOSのUI構築小技集(小さなとこから始められる編)
iOSのUI構築小技集(小さなとこから始められる編)iOSのUI構築小技集(小さなとこから始められる編)
iOSのUI構築小技集(小さなとこから始められる編)
 
Extra view @ kyobashi.swift
Extra view @ kyobashi.swiftExtra view @ kyobashi.swift
Extra view @ kyobashi.swift
 
Knockout
KnockoutKnockout
Knockout
 
UIImagePickerController よもやま話
UIImagePickerController よもやま話UIImagePickerController よもやま話
UIImagePickerController よもやま話
 
Mapkitframework io9week
Mapkitframework io9weekMapkitframework io9week
Mapkitframework io9week
 
WKWebViewとUIWebView
WKWebViewとUIWebViewWKWebViewとUIWebView
WKWebViewとUIWebView
 
iOS WebView App
iOS WebView AppiOS WebView App
iOS WebView App
 
UIViewController のコンテナ機能
UIViewController のコンテナ機能UIViewController のコンテナ機能
UIViewController のコンテナ機能
 
デザイナーとエンジニアが話す、iOSアプリケーション開発
デザイナーとエンジニアが話す、iOSアプリケーション開発デザイナーとエンジニアが話す、iOSアプリケーション開発
デザイナーとエンジニアが話す、iOSアプリケーション開発
 
魅せるUIの作り方 | iOS 7エンジニア勉強会
魅せるUIの作り方 | iOS 7エンジニア勉強会魅せるUIの作り方 | iOS 7エンジニア勉強会
魅せるUIの作り方 | iOS 7エンジニア勉強会
 
UIViewController in XIB + IBDesignable
UIViewController in XIB + IBDesignableUIViewController in XIB + IBDesignable
UIViewController in XIB + IBDesignable
 

Último

Último (12)

論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
NewSQLの可用性構成パターン(OCHaCafe Season 8 #4 発表資料)
 
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
Observabilityは従来型の監視と何が違うのか(キンドリルジャパン社内勉強会:2022年10月27日発表)
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 

よこへな3 15発表資料 最近ViewController をどんな感じで書いているか