【Swift】API利用アプリのサンプルコード(Storyboard未使用、PureLayout)
2954 ワード
概要
YahooオークションのAPIを2つ利用した簡単なアプリのサンプルコードです。
カテゴリ情報APIにてカテゴリの一覧を取得して、
TableViewに「カテゴリ名、商品数」を表示します。
末端カテゴリのときは商品リストAPIにて商品一覧を取得して、
CollectionViewに「商品画像、商品名、価格、残り時間、入札数」を表示します。
github
結果
Auto Layout設定
- tableViewCell
private func addConstraints() {
categoryLabel.autoAlignAxisToSuperviewAxis(.Horizontal)
categoryLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: 15.0)
categoryLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 15.0)
}
- collectionViewCell
private func addConstraints() {
itemImageView.autoPinEdgeToSuperviewEdge(.Top, withInset: 2)
itemImageView.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
itemImageView.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
titleLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: itemImageView, withOffset: 3.0)
titleLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
titleLabel.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
priceLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: 3.0)
priceLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
priceLabel.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
endTimeLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: priceLabel, withOffset: 3.0)
endTimeLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
endTimeLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 5)
bidLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: priceLabel, withOffset: 3.0)
bidLabel.autoPinEdge(.Left, toEdge: .Right, ofView: endTimeLabel, withOffset: 10.0)
bidLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 5)
}
private func addConstraints() {
categoryLabel.autoAlignAxisToSuperviewAxis(.Horizontal)
categoryLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: 15.0)
categoryLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 15.0)
}
private func addConstraints() {
itemImageView.autoPinEdgeToSuperviewEdge(.Top, withInset: 2)
itemImageView.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
itemImageView.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
titleLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: itemImageView, withOffset: 3.0)
titleLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
titleLabel.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
priceLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: 3.0)
priceLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
priceLabel.autoPinEdgeToSuperviewEdge(.Right, withInset: 2)
endTimeLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: priceLabel, withOffset: 3.0)
endTimeLabel.autoPinEdgeToSuperviewEdge(.Left, withInset: 2)
endTimeLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 5)
bidLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: priceLabel, withOffset: 3.0)
bidLabel.autoPinEdge(.Left, toEdge: .Right, ofView: endTimeLabel, withOffset: 10.0)
bidLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 5)
}
Author And Source
この問題について(【Swift】API利用アプリのサンプルコード(Storyboard未使用、PureLayout)), 我々は、より多くの情報をここで見つけました https://qiita.com/menomoto/items/67fb1fec12d444072ed6著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .