iOSエンジニアのつぶやき

毎朝8:30に iOS 関連の技術について1つぶやいています。まれに釣りについてつぶやく可能性があります。

【Git】コンフリクトした際にどちらかの変更を全面的に取り入れる

stash pop でコンフリクトした際に、どちらか一方の変更を適用するのどうやるんだっけ?っとなったので軽くメモ🔰

結論

現在チェックアウトしているブランチの変更を適用する場合は、下記のようにcheckout --oursを使用します。

$ git checkout --ours Hoge.swift

マージするブランチ側の変更を適用する場合は、下記のようにcheckout --theirsを使用します。

$ git checkout --theirs Hoge.swift

てな感じで本日も以上となります🍺

その他の記事

yamatooo.blog

yamatooo.blog

yamatooo.blog

【CSS】height:100% が効かん!

特定の要素をブラウザ画面の高さで表示したい時に、CSSで指定したheight: 100%が効かなかったので、メモ🔰

結論

下記のようにhtmlbody要素にheight: 100%を設定することで、ブラウザ画面から相対的に高さを計算することができるようになります。ちなみに、一つ上の階層(コンテナとなる要素)に、高さ指定がされていない場合は、height: autoとして計算されるそうです。

html {
  height: 100%;
}

body {
  height: 100%;
}

てな感じで本日も以上となります🍺

参考

qiita.com

その他の記事

yamatooo.blog

yamatooo.blog

yamatooo.blog

htmlのbutton無効時のカラー調整

結論

cssからbutton:disabledで無効時のデザインを設定することができます🔰

button:disabled {
  border: 1px solid #999999;
  background-color: #cccccc;
  color: #666666;
}

ちなみに、ホバー時やボタン押下時なども同様に設定できます.

button:hover {
  border: 1px solid #0099cc;
  background-color: #00aacc;
  color: #ffffff;
  padding: 5px 10px;
}


button:active {
  background-color: #00aacc;
}

てな感じで本日も以上となります🧑‍🔧

その他の記事

yamatooo.blog

yamatooo.blog

yamatooo.blog

【Swift】Array to Dictionary メモ

ArrayからDictionary変換したい時って、どうやったらシンプルにできるんだっけ?っていうのを忘れていたのでメモ👷‍♀️

結論

reduce使えばええやん🛠 ちなみにクロージャの引数になるdictは定数なので、新しい変数を作ってデータを追加していく必要があります。

    let dic: [String: [Int]] = $0.reduce([String: [Int]]()) { dict, data in
        var newDict = dict
        newDict[data.id] = data.number
        return newDict
    }

てな感じ本日も以上となります🍺

その他の記事

yamatooo.blog

yamatooo.blog

yamatooo.blog

【Swift】Viewの一部だけを角丸にしたい

結論

右下を角丸にする場合は、下記のように指定することで一部を角丸にできます。コードを見ればわかるように、maskedCornersは配列で指定することができるので、角丸にする部分を組み合わせることもできます。

view.layer.cornerRadius = 10
view.layer.maskedCorners = [.layerMaxXMaxYCorner]

ちなみに、四隅の対応は下記のようになっています。

場所 CACornerMask
左上 .layerMinXMinYCorner
右上 .layerMaxXMinYCorner
左下 .layerMinXMaxYCorner
右下 .layerMaxXMaxYCorner

てな感じで本日も以上となります🍺

その他の記事

yamatooo.blog

yamatooo.blog

yamatooo.blog

【Xcode】imageやcolorをソースコード上に表示するTips

本日はXcodeの小ネタです🛠

imageやcolorをソースコード上に表示する

Xcode8によって追加された機能により、ソースコード上にimageやcolorを表示しながらセットすることができます。

f:id:yum_fishing:20210811180620p:plain

この機能はImage LiteralColor Literalを選択することで、下記のように使えます。

f:id:yum_fishing:20210811180843p:plain

ちなみに実体は#imageLiteral#colorLiteralなので、それらを直接記述しても表示することができます。

#imageLiteral(resourceName: "Icon")

てな感じで本日も以上となります🍺

その他の記事

yamatooo.blog

yamatooo.blog

yamatooo.blog

【Swift】Cellをコードベースで構築する際にやらかした

久しぶりにUICollectionViewCellの実装をコードベースで行ったら、初心者みたいなやらかしをしたのでメモ👷‍♀️

やらかし

やらかしの一部がこちら。そうです、動的にCellの高さが変わるような場合に、Cellが再利用されるタイミングでImageViewのframeが以前のcontentView.frameのままになるので、予期しないサイズでImageViewが表示されます。

class Cell: UICollectionViewCell {

    private lazy var imageView: UIImageView = {
        let imageView = UIImageView(frame: contentView.frame)
        imageView.contentMode = .scaleAspectFill
        imageView.clipsToBounds = true
        imageView.layer.cornerRadius = 16
        return imageView
    }()

修正

いつもxibでやっているように、今回はAutoLayoutで制約を張ることで問題を解消しました🤮

        contentView.addSubview(imageView)
        imageView.translatesAutoresizingMaskIntoConstraints = false
        imageView.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
        imageView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor).isActive = true
        imageView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor).isActive = true
        imageView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true

てな感じで本日も以上となります🍺

その他の記事

yamatooo.blog

yamatooo.blog

yamatooo.blog