【objective-c】アラート ios objective-c
今更ながらobjective-cでのアラートをメモ。
よく忘れるので。
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"タイトル" message:@"メッセージ?" preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"キャンセル" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]]; [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // ボタンを押した場合の処理を記述する }]]; [self presentViewController:alert animated:YES completion:nil];
【swift】attributedTextで装飾
let text = "aaaaaaaa" let attrText = NSMutableAttributedString(string: text) let attributes = [NSFontAttributeName:UIFont.systemFontOfSize(detailFontSize*2, weight:UIFontWeightThin)] attrText.addAttributes(attributes, range: NSMakeRange(text.characters.count-1, 1)) label.attributedText = attrText
【swift】UITextFieldがキーボードで隠れる場合の対処法
メモメモ
参考サイト
qiita.com
【swift】 UILabelのfontにstyleを適用する方法
XcodeでのUILabelのフォントでstyleを指定できるのにコードではそれらしきものが見つからなくて調べた。メモ
参考ページ:
stackoverflow.com
// Weights used here are analogous to those used with UIFontDescriptor's UIFontWeightTrait. // See the UIFontWeight... constants in UIFontDescriptor.h for suggested values. // The caveat above about the use of ...systemFont... methods applies to these methods too. @available(iOS 8.2, *) public class func systemFontOfSize(fontSize: CGFloat, weight: CGFloat) -> UIFont
上記のメソッドを使うとできるみたい。
ios8.2以上対応みたいですね!
weightにて指定できるのは以下
UIFontWeightUltraLight UIFontWeightThin UIFontWeightLight UIFontWeightRegular UIFontWeightMedium UIFontWeightSemibold UIFontWeightBold UIFontWeightHeavy
実際の指定方法は↓
label.font = UIFont.systemFontOfSize(17.0, weight: UIFontWeightThin)
以上。
swift2.0 メールを送信する
まずは準備
import MessageUI class ViewController: UIViewController,MFMailComposeViewControllerDelegate { ・ ・ ・ func sendMail() { //メールを送信できるかチェック if MFMailComposeViewController.canSendMail()==false { print("Email Send Failed") return } let mailViewController = MFMailComposeViewController() let toRecipients = ["test@test.com"] mailViewController.mailComposeDelegate = self mailViewController.setSubject("メールの件名") mailViewController.setToRecipients(toRecipients) //宛先メールアドレスの表示 mailViewController.setMessageBody("メールの本文", isHTML: false) self.presentViewController(mailViewController, animated: true, completion: nil) } func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) { switch result.rawValue { case MFMailComposeResultCancelled.rawValue: print("Email Send Cancelled") break case MFMailComposeResultSaved.rawValue: print("Email Saved as a Draft") break case MFMailComposeResultSent.rawValue: print("Email Sent Successfully") break case MFMailComposeResultFailed.rawValue: print("Email Send Failed") break default: break } self.dismissViewControllerAnimated(true, completion: nil) }
【Swift】初めのSwift言語。
久々にブログを更新します。
今回は、iPhoneアプリを作る為の新しい言語「Swift」を学びました。
今までの「objective-c」言語との違いをまとめようと思います。
========================================
参考サイト↓
まず、Appleの公式ドキュメント
The Swift Programming Language: The Basics
Swift (プログラミング言語) - Wikipedia
========================================
上記のサイトでswift言語を確認しました。
ざっと確認したところ大きく分けて3つの違いがありました。
- 型の指定方法の違い
- 命令文の最後の「;」(セミコロン)がいらない
- ポインタの概念がなくなった? 「*」がいらない
っていうところかな。
今までは、データ型やクラスを宣言する場合は「int」「NSString」とか使っていたと思います。
それが「var」変数の場合、「let」定数の場合で分けて書くようになってました。
・objective-cの場合
int count = 0;
const NSString *str = @"テスト";
・swiftの場合
var count = 0
let str = "テスト"
こんな書き方で、「;」「*」がいらない。
これは書き方が簡単になったなー。
コンパイラーが型を判断してくれて、メモリも管理してくれるようになっていらなくなったみたい。
これからswiftでアプリを作っていかねば。
勉強するぞ。