[objective-c]UILabelの文字間を設定

UILabelの文字間を設定

-(void)setLetterSpacing:(UILabel*)label letterSpacing:(float)letterSpacing{
    NSMutableAttributedString* attributedText= [[NSMutableAttributedString alloc] initWithString:label.text];
    [attributedText addAttribute:NSKernAttributeName
                           value:[NSNumber numberWithFloat:letterSpacing]
                           range:NSMakeRange(0, attributedText.length)];
    label.attributedText = attributedText;
}

[objective-c]UILabelの行間を設定

UILabelの行間を設定

-(void)setLineHeight:(UILabel*)label lineHeight:(float)lineHeight{
    NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
    paragrahStyle.minimumLineHeight = lineHeight;
    paragrahStyle.maximumLineHeight = lineHeight;
    NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:label.text];
    [attributedText addAttribute:NSParagraphStyleAttributeName
                           value:paragrahStyle
                           range:NSMakeRange(0, attributedText.length)];
    label.attributedText = attributedText;
}

[CakePHP 2.x]DBを切替える

DB設定を記述する。

Config/database.php

public $default = array(
	'datasource' => 'Database/Mysql',
	'persistent' => false,
	'host' => 'localhost',
	'login' => 'ktyr',
	'password' => 'ktyrps',
	'database' => 'ktyrdb',
	'prefix' => '',
	'encoding' => 'utf8',
);
public $testdb = array(
	'datasource' => 'Database/Mysql',
	'persistent' => false,
	'host' => 'localhost',
	'login' => 'ktyr',
	'password' => 'ktyrps',
	'database' => 'ktyrtestdb',
	'prefix' => '',
	'encoding' => 'utf8',
);

DBを切替える。
各Model内で切替える場合。

/* testdbに切替える */
$this->setDataSource('testdb');

/* defaultに切替える */
$this->setDataSource('default');

[CakePHP 2.x]トランザクション

各Model内

/* トランザクションスタート */
$dataSource=$this->getDataSource();
$result=$dataSource->begin();

/* コミット */
$result=$dataSource->commit();

/* ロールバック */
$result=$dataSource->rollback();

AppModel.phpに下記のようにするのもいいかもね。

public function begin(){
  return $this->getDataSource()->begin();
}
public function commit(){
  return $this->getDataSource()->commit();
}
public function rollback(){
  return $this->getDataSource()->rollback();
}

[MySQL]2テーブルの差分取得

同定義のテーブルA、テーブルBにおいて
テーブルAにあり、テーブルBに無いデータのidを取得する。

SELECT id FROM テーブルA WHERE NOT EXISTS (SELECT id FROM テーブルB WHERE テーブルB.id = テーブルA.id) ORDER BY id