UITextFieldに余白をつけて良い感じの表示にする【サンプルコード】

iPhone

UITextFieldを使うと、文字が上に、左に寄っていて見た目が悪い。
その場合、左に余白をつけ、文字を縦中央にしたら良い感じに鳴ります。

 UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 30)];
 paddingView.opaque = NO;
 paddingView.backgroundColor = [UIColor clearColor];
 textField.leftView = paddingView;
 textField.leftViewMode = UITextFieldViewModeAlways;
 textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

UITextViewに閉じるボタンをつける

iPhone

// ツールバーの作成
viewdidloadに、

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolBar.barStyle = UIBarStyleBlackOpaque; // スタイルを設定
[toolBar sizeToFit];

// フレキシブルスペースの作成(Doneボタンを右端に配置したいため)
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] UIBarButtonItemSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

// Doneボタンの作成
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(closeKeyboard:)];

// ボタンをToolbarに設定
NSArray *items = [NSArray arrayWithObjects:spacer, done, nil];
[toolBar setItems:items animated:YES];

// ToolbarをUITextFieldのinputAccessoryViewに設定
テキストビュー.inputAccessoryView = toolBar;
}

  • (void)closeKeyboard:(id)sender{

[テキストビュー resignFirstResponder];
}

Ubuntu 16.10 Network Interfaceを追加する

Linuxサーバー

さくらインターネットVPSにUbuntu 16.10をインストールし、コントロールパネルからスイッチを追加しました。

Ubuntuサーバー側では下記のように新しいネットワークインターフェイス設定を追加してネットワークを再起動します。

 # sudo vim /etc/network/interfaces.d/private
 auto ens4
 iface ens4 inet static
         address 192.168.1.11
         netmask 255.255.255.0
         network 192.168.1.0
         broadcast 192.168.1.255
 # sudo systemctl networking restart

Unable to add window

Android

Android エラー Unable to add window

サービス内で、AlertDialogを出そうとしたところ次のようなエラーが出てしまいました。

 android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

どうやら、サービス内で、AlertDialogは出せないようです。
Activityを起動して、そこでAlertDialogを出すのがよさそうです。

Unable to connect to ssl//gateway.push.apple.com 2195 Unable to find the socket transport ssl

iPhone
PHP

Unable to connect to ‘ssl://gateway.push.apple.com:2195’: Unable to find the socket transport “ssl” – did you forget to enable it when you configured PHP?

上記のようなエラーが出て、APNSでAppleのサーバーに接続できなかった時はPHPの設定ファイルのphp.iniに、下記を付け加えましょう。

extension=php_openssl.dll

Apacheを再起動するのも忘れずに☆