投稿

UIViewを角丸にしようとしてもdraw(_ rect: CGRect)をオーバーライドしたら四角になる

Xcode 10.1 Swift 4.2 UIViewの角丸は class MyView: UIView { init() { super.init(frame: .zero) self.backgroundColor = UIColor.white self.layer.cornerRadius = 10.0 } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } } とすると出来る。 しかし次のように override func draw(_ rect: CGRect) を書いてしまうとダメになる。 class MyView: UIView { init() { super.init(frame: .zero) self.backgroundColor = UIColor.white self.layer.cornerRadius = 10.0 } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func draw(_ rect: CGRect) { super.draw(rect) } } この場合、self.clipsToBounds = trueをinit()などに書いてやると丸く収まる。 しかし、viewにシャドウを付ける場合はself.clipsToBounds = trueによってシャドウが消える。角丸にしてシャドウをつけるのはよくあるので困る。

MPMusicPlayerControllerのappendQueueDescriptor

MPMusicPlayerControllerのappendQueueDescriptorは仕様上はiOS10.3からだが、iOS10.3ではうまく機能しない。iOS11以降はOK.。 // Adds the contents of the queue descriptor to the end of the queue - (void)appendQueueDescriptor:(MPMusicPlayerQueueDescriptor *)descriptor MP_API(ios(10.3));

Validation出来ない症状

イメージ
Xcode 9にしてから何かと不便が多い。 今度はアプリをAppleに送る前のValidationが出来ない症状になった。Uploadも無理。 No accounts with iTunes Connect access have been found for アカウント名(チーム名?) iTunes Connect access is required for Apple Store distribution. No iTunes Connect access for the team. 少し古いプロジェクトは大丈夫だったのにちょっとソースを変更したらいきなりこの症状である。 対策(と言えるのか?) 大丈夫だったプロジェクトでvalidationを行うとうまくいった。 その後、問題のあるプロジェクトでvalidationを行うと今度はうまくいった。

Xcode 9でInstrumentsが実行できない不具合

イメージ
Xcode 9からの不具合なのかInstrumentsが実行できない状態になりました。 録画ボタンのような赤丸をクリックして開始しようとすると Permission to debug xxx.xxxx.xxx was denied. と表示されて開始しません。 以下の作業をしたら治りました。XcodeのPreferenceで - Preference -> Locations -> Command Line ToolsをXcode 8.3.3に切り替え - Instruments立ち上げ - エラーが出る - Preference -> Locations -> Command Line ToolsをXcode 9.0.1に切り替え 追記 別のプロジェクトで引き続き不具合が出るので治っていませんでした。

iOSで使えるフォント UIFontのfontName一覧 iOS11版

参考記事 Over&Out その後 UIFontのfontName一覧 これのiOS11版を行います。 今回はSwiftで書きました。 //Swift 4.0 let familyNames = UIFont.familyNames for aFamilyName in familyNames.sorted() { print(aFamilyName) for aFontName in UIFont.fontNames(forFamilyName: aFamilyName) { print("--", aFontName) } } ちなみに下はフォントの使用例です。 let myFont = UIFont(name: "AcademyEngravedLetPlain", size: 24) 結果 Academy Engraved LET -- AcademyEngravedLetPlain Al Nile -- AlNile -- AlNile-Bold American Typewriter -- AmericanTypewriter-CondensedBold -- AmericanTypewriter-Condensed -- AmericanTypewriter-CondensedLight -- AmericanTypewriter -- AmericanTypewriter-Bold -- AmericanTypewriter-Semibold -- AmericanTypewriter-Light Apple Color Emoji -- AppleColorEmoji Apple SD Gothic Neo -- AppleSDGothicNeo-Thin -- AppleSDGothicNeo-Light -- AppleSDGothicNeo-Regular -- AppleSDGothicNeo-Bold -- AppleSDGothicNeo-SemiBold -- AppleSDGothicNeo-UltraLight -- AppleSDGothicNeo-Medium Arial --...

Xcodeのフォント/色の設定の変更が効かない

イメージ
Xcodeにはフォント/色を変える機能があります。 ところが、最近これがうまく効かなくなってしまいました。Xcodeのバージョンは9.0です。 いらないものを消しても、次にXcodeを起動した時に復活してきます。 自分が取った対策は以下です。 今までに自分で作った設定をどこかにメモして ~/Library/Developer/Xcode/UserData/FontAndColorThemes の中を全て削除して初期状態にし、その後Xcode上で必要なものを作り直す。 ~は/Usersの下の自分フォルダです。煙突が付いた家のアイコンのやつです。 ~/Libraryは普通は見えないのでForkLiftというソフトを使いました。あるいは、optを押しながらFinderのGoをクリックすると出てきます。 画像ではoptを押してないです。optを押すとスクリーンショットが取れなかったので。 参考 https://qiita.com/Humangas/items/420ae56cc6db2d3d998d

Auto Layoutで発生する黄色の警告

イメージ
Auto Layoutで発生する黄色の警告は、自動修正機能がある。この自動修正機能は、エラーのあるソースコードに対するFixボタンのようなもの。以下は、この自動修正を行ったレポートである。なぜその警告が出るかはわからないのでひとまず置いといて、自動修正を行ったときの挙動を報告するものである。使用したXcodeのバージョンは9.0。 LeadingとTrailingに対するConstraint警告 Xcode9で既存のプロジェクトを開くとこんな警告が出ました。 Fixed leading and trailing constraints may cause clipping, one of them should have a constant ≥ standard space. 選択肢1 : Use Fixed Leading and Resizing Trailing Constraints Adjust to include a fixed leading constraint and a trailing constraint with a constant ≥ standard space. Recommended if the view is on the left half of the parent view. 選択肢2 : Use Resizing Leading and Fixed Trailing Constraints Adjust to include a leading constraint with a constant ≥ standard space and a fixed trailing constraint. Recommended if the view is on the right half of the parent view. 文を読んでも何を言っているかわからないので、簡単なプロジェクトを作ってテストしました。メインのviewの上にラベルを一つ置くものです。ラベルと親viewとの間にleadingとtrailingの制約を付けました(他の制約を述べるのは割愛)。この警告はleadingとtrailingのどちらかを26以上にすると発生しました。どちらかを26以上にしただけで両方の選択肢が出てきます。...