昔、書いたような気がしなくもないのですが、jQueryを使ってbackground-imageを削除したい場合は、どうすればいいのだろうか?
いくつか調べてみて下のようにすれば削除できるようです。
$('#hoge').css('background-image','none');最初、
$('#hoge').css('background-image','');でやっても削除されなかったので、何故かなーっと疑問に思っていたのですが、解決できてほっとしましたー。
常にテンパってます。
昔、書いたような気がしなくもないのですが、jQueryを使ってbackground-imageを削除したい場合は、どうすればいいのだろうか?
いくつか調べてみて下のようにすれば削除できるようです。
$('#hoge').css('background-image','none');最初、
$('#hoge').css('background-image','');でやっても削除されなかったので、何故かなーっと疑問に思っていたのですが、解決できてほっとしましたー。
Task Queue Python API Overview
と
Using Push Queues in Python
を読みながら「Task Queue」の使い方を勉強してみた。
基本的に、「Task Queue」は
Push Queues
と
Pull Queues
に分かれており、デフォルトは、Push QueuesでFIFOでタスクを処理してくれる。
しかも、プログラムがめちゃくちゃ簡単で、Queueの名前をつけなくても実行することができちゃう。
こんな感じです。
import webapp2 from google.appengine.api import taskqueue class HogeHandler(webapp2.RequestHandler): def get(self): # Add the task to the default queue. taskqueue.add(url='/bar', params={'key': key})たったのこれだけでできてしまう。
class BarHandler(webapp2.RequestHandler): def post(self): key = self.request.get('key')で、受け取ることができます。
昔に書いたエントリーにあるかなーっと思って探したら見当たらなかったので、ちょっと書いてみる。
checkboxのcheckをはずすためのソースは、How to check and uncheck a checkbox with jQueryにもあったが、下のようにできる。
$('input[name="checkbox"]').attr('checked',false);
どうやらもはやGoogle Site上でGoogle AdSenseが利用できなくなるかもしれない。
一時はGoogle Site結構使っていたけど、最近は、ピタリと使わなくなったからたいしたことないと言えば、ないんだけど。Starting August 30th 2013, it will no longer be possible to modify AdSense ad code on Google Sites pages. However, any ads you’ve previously placed on Google Sites will continue to show, and you’ll be credited for all valid earnings.
via:Changes to AdSense on Google Sites
No change is required on the part of AdSense users. Any ads that you currently have running will not be altered or removed, though you’ll be free to delete ads yourself. However, it will no longer be possible to edit or add new AdSense ads to your existing Google Sites site or to new pages.
ちょっとこれほしいかも。
これ、スマホでゲームをやったり動画を見たりする人にとっては便利なアイテムではないだろうか?GoogleからChromecastが登場した。名前でも推測できるとおり、GoogleのChromeブラウザ/OSをベースにして家庭の大型テレビにクラウドからコンテンツをストリーミングするデバイスだ。
via:Google、Chromecastを35ドルで今日から発売―居間のテレビに取り付けるとビデオコンテンツをストリーミング受信できる
TTTAttributedLabelの実装方法を紹介しましたが、上寄せにすることはできないのだろうか?
TTTAttributedLabelの実装ファイルをみたらやり方が書いてあった。
self. verticalAlignment = TTTAttributedLabelVerticalAlignmentTop;でいけるっぽい。
前回、Yahooが作ったCSSライブラリのPureを紹介しましたが、ちょっと興味があり勉強することに。
って、まずは、CSSを使うわけだが、ダウンロードしてサーバーにアップして使うにはめんどいなーっと思って、CDNないかなーっと思っていたらありました。
下のように記述すれば使えるようにです。
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.2.1/pure-min.css">
先日、BootStrap3がリリースされたことを書きましたが、フラットデザインが採用されているBootstrapベースにフレームワークが公開されていることが、BootstrapベースのフラットUI実装フレームワーク「Furatto」で知ったのですが、3のサイトを見ているとフラット系のデザインになっているような気がして、デフォルトのものを使った方がよかったりして。
果たしてどうなのだろうか?
md5を使ってハッシュ化をするにはどうすればいいのだろうか?
マニュアルを見て確認。
import md5 m = md5.new() m.update(" the spammish repetition") m.hexdigest()これでhash化も困らないぞと。
前回、TTTAttributedLabelの適用方法を書きましたが、今回はリンクの設定について
CGRect rect; TTTAttributedLabel *tTTAttributedLabel = [[TTTAttributedLabel alloc] initWithFrame:rect]; tTTAttributedLabel.backgroundColor = [UIColor clearColor]; tTTAttributedLabel.font = [UIFont systemFontOfSize:10]; tTTAttributedLabel.lineBreakMode = UILineBreakModeTailTruncation; tTTAttributedLabel.textColor = [UIColor redColor]; tTTAttributedLabel.textAlignment = UITextAlignmentLeft; tTTAttributedLabel.numberOfLines = 0; UIColor *fontColor; 出力したい文字列 NSString *newDispComment; [tTTAttributedLabel setText:newDispComment afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) { //途中で色を変更する NSUInteger toIdx; NSRange colorChangeRange = [[mutableAttributedString string] rangeOfString:username options:NSCaseInsensitiveSearch range:NSMakeRange(0, toIdx)]; [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[fontColor CGColor] range:colorChangeRange]; return mutableAttributedString; }]; tTTAttributedLabel.delegate = self; //リンクの設定 NSString moveToURL; NSUInteger toIdx; [tTTAttributedLabel addLinkToURL:[NSURL URLWithString:moveToURL] withRange:NSMakeRange(0,toIdx)];こうすることによって、ある特定の位置をタッチした場合のリンク処理を追加することができて、実際にタッチした場合は、delegateメソッドの- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)urlが呼ばれるので、そこで処理を実行すればいい。
NSMutableDictionary *mutableLinkAttributes = [NSMutableDictionary dictionary]; [mutableLinkAttributes setValue:[NSNumber numberWithBool:NO] forKey:(NSString *)kCTUnderlineStyleAttributeName]; tTTAttributedLabel.linkAttributes = mutableLinkAttributes;で実現することができる。リンクの色を変更したい場合は、
//リンクの色 NSMutableDictionary *mutableActiveLinkAttributes = [NSMutableDictionary dictionary]; [mutableActiveLinkAttributes setValue:(id)[fontColor CGColor] forKey:(NSString *)kCTForegroundColorAttributeName]; tTTAttributedLabel.activeLinkAttributes = mutableActiveLinkAttributes;で変更することができます。
iOS5対応のアプリを作る時に困るのは、NSStringやUILabelを使って文字列を出力する時に、途中で、色をかえたり、リンクを追加するのが非常にめんどいということ。
CoreTextを使えばできるのだが、めんどいのでオープンソースでカバーできないかなーっと思っていたら、
TTTAttributedLabel
という素敵なコードがあったので、適用方法を勉強することに。
基本的には、githubのソースを見ればいいのだが、下のような感じで使うことができる。
CGRect rect; TTTAttributedLabel *tTTAttributedLabel = [[TTTAttributedLabel alloc] initWithFrame:rect]; tTTAttributedLabel.backgroundColor = [UIColor clearColor]; tTTAttributedLabel.font = [UIFont systemFontOfSize:10]; tTTAttributedLabel.lineBreakMode = UILineBreakModeTailTruncation; tTTAttributedLabel.textColor = [UIColor redColor]; tTTAttributedLabel.textAlignment = UITextAlignmentLeft; tTTAttributedLabel.numberOfLines = 0; UIColor *fontColor; 出力したい文字列 NSString *newDispComment; [tTTAttributedLabel setText:newDispComment afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) { //途中で色を変更する NSUInteger toIdx; NSRange colorChangeRange = [[mutableAttributedString string] rangeOfString:username options:NSCaseInsensitiveSearch range:NSMakeRange(0, toIdx)]; [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[fontColor CGColor] range:colorChangeRange]; return mutableAttributedString; }];こんな風に実装すれば、文字列の途中で色を変更することは可能です。
前回、認証の方法をさらっと書きましたが、今回は、usernameとidの取得方法について。
#import <Accounts/Accounts.h> ACAccountStore *aCAccountStore = [[ACAccountStore alloc] init]; ACAccountType *aCAccountType = [aCAccountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [aCAccountStore requestAccessToAccountsWithType:aCAccountType withCompletionHandler:^(BOOL granted, NSError *error) { if (granted) { NSArray *account = [aCAccountStore accountsWithAccountType:aCAccountType]; NSUInteger count = [account count]; for (NSUInteger i=0; i<count; i++) { ACAccount *acAccount = [account objectAtIndex:i]; NSLog(@"twitter id is %@",[acAccount valueForKeyPath:@"properties.user_id"]); NSLog(@"username is %@",acAccount.username); } }else{ NSLog(@"not grandted"); } }];usernameはACAccountに記述されていたから問題はなかったのですが、user_idは迷いました。
NSString *idStr = [self valueForKeyPath:@"properties.user_id"];という記述が書いてあったので、NSObjectクラスに標準装備されているvalueForKeyPathメソッドを使って取得することができましたー。
読了
お金が教えてくれること ~マイクロ起業で自由に生きる~
家入 一真
ペパボの創業者ということで、興味があり手に取ってみることに。はじめにーお金の話しをする前に。
via:目次
01 ~お金との付き合い方~ お金に「思考」を奪われない
絶対知っておくべき 「いくら稼ぐか」
妄想貧乏に陥らない
お金に「思考」を奪われない
「あの時、お金があったら」
十数億円あっても、お金はなくなる
お金に代わる価値を持つ
評価経済のなかのお金の価値
消費時代の終焉
02 ~お金の使い方~ キャリアの借金
今しかない時間を買う
カッコいいお金の使い方
不満や愚痴にお金を費やさない
投資の醍醐味は人と場所
貯金はないけど「おもしろい人間」
03 ~給料に依存しない働き方~ 最大のリスクは「何もしない」こと
雇われるリスクを考えてみる
給料0円でも働きたくなる仕事
会社じゃない組織の可能性
「何もしない」はもはやリスクでしかない
仕事をおもしろくするのがクリエイティブ
仕事は会社のなかに落ちているわけじゃない
04 ~お金の稼ぎ方~ 小さく始めて小さく稼ぐマイクロ起業
とりあえずやってみる
「何もない」は「何でもできる」ってこと
肩書きで、人は変わることもある
「やらない理由」を考えない
「新しいアイデア」より「見せ方」を考える
1を100にしてくれるフォロワーを作る
05 ~ビジネスの描き方~ ストーリーを売る
ビジネスはもっと自由でアートでいい
わがままな経営者になる
「儲かりそうだから」ではビジネスにならない
ものを売るのではなく、ストーリーを買わせる
お金だけじゃなく、ファンも集めよう
100円マックに文句言うな
06 ~人生の転がり方~ 失敗しても、最悪死なない
失敗したら「成長できる」
気の弱いリーダーですみません
プライドは役に立たない
借金なんて怖くない
経営者であっても、会社にしがみつかない
執着心は捨てる
ゼロになったら、また1にすればいい
「個の時代」がやって来た
後書きーそれでもお金は必要。
iOS5からtwitterの認証がデフォルトで装備されましたが、一体どうやって使うの?
色々調べた結果、めちゃくちゃ簡単に使えることが判明。
#import <Accounts/Accounts.h> ACAccountStore *aCAccountStore = [[ACAccountStore alloc] init]; ACAccountType *aCAccountType = [aCAccountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]; [aCAccountStore requestAccessToAccountsWithType:aCAccountType withCompletionHandler:^(BOOL granted, NSError *error) { if (granted) { NSLog(@"grandted"); }else{ NSLog(@"not grandted"); } }];AccountsFrameworkをインポートして上のようにコードすればおk
昨日、BootStrap3のリリース書きましたが、Getting startedを読んでいたら、どうやらCDNがサポートされている模様。
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/css/bootstrap.min.css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0-rc1/js/bootstrap.min.js"></script>前からサポートしてほしいなーっと思っていたのだが、他にも声があったのだろうか?
Richer access to Google services and better OS integration in Chrome packaged appsを読んで知ったのですが、どうやらDeveloper版のpackaged appsで、Media Gallery APIを使ってiTunesのデータを読みこむことができるようです。
久しぶりにchrome web apps作りたくなってきたなー。
早く安定版でも実装してほしいです。
twittterのように入力文字を制限したい場合はどうすればいいのだろうか?
Set the maximum character length of a UITextField
にやり方が書いてあったので、基本的には、それを使えばおk
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ NSUInteger newLength = [textView.text length] + [text length] - range.length; return (newLength > kMaxLengthTextView) ? NO : YES; }これでtwitterのように文字数制限したい場合も困らないぞと。
Instagramのコメント投稿画面のようにキーボートのすぐ上にテキストボックスを設置したい場合、どうすればいいのだろうか?
(ちなみに、facebookでは下のような感じになる。)
Text, Web, and Editing Programming Guide for iOSを読むと、デフォルトでは216pxって書いてあるんだけど、日本語の推測変換が表示された場合、あきらかにそれ以上のようなwww
ってことで、通知してくれるdelegate機能みないなのってないのかなーっと思っていたらありました。
UIKeyboardWillShowNotification
UIKeyboardDidShowNotification
UIKeyboardWillHideNotification
UIKeyboardDidHideNotification
マニュアルを読むとUIWindowの中にあったので、UIWindowが通知してくれるのかな?
まーあまり細かいことを考えずに、下のようなソースで実装することができましたー。
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShown:) name:UIKeyboardWillShowNotification object:nil]; } -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; } -(void)keyboardWillShown:(NSNotification*)note{ NSDictionary* info = (NSDictionary*)[note userInfo]; CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size; //Comment部分の位置の調節(kbSize.heightはキーボードの高さ) baseCommentView.frame = CGRectMake(0, (self.view.frame.size.height - kbSize.height - baseCommentView.frame.size.height), baseCommentView.frame.size.width, baseCommentView.frame.size.height); }これで、動的に位置が変わるテキストボックスの設置にも困ることはありませんね。
UITabBarItemにアイコン(画像)を設定することができるのですが、文言(タイトル)抜きにした場合、ちょっと上気味になってしまいます。
そこで、ど真ん中にするにはどうすればいいのだろうか?
「UITabBarItemのカスタマイズをタイトル含めた一枚画像で行う」を読むと、UIBarItemのimageInsetsプロパティを使えばいいことがわかりました。
同エントリーでは、プロパティの各値に直接設定をしていたが、下のように構造体を使うことも可能。
tabBarItem.imageInsets = UIEdgeInsetsMake(3,0,-3,0);これで、Pinterestのようなアイコンが真ん中にきているアプリを実装できるぞと。
素敵!!
欲望のマーケティング (ディスカヴァー携書)
山本 由樹
どういうきっかけで本書を知ったか忘れてしまったが、久しぶりの良書。PART1 本当の欲望を聞き出せているか?
via:目次
PART2 絞り込めているか?
PART3 巻き込めているか?
PART4 揺るがせているか?
iOS5までは、UITextViewにplaceholderを設定することができないのですが、それに近い機能は実装したいなーっと思って、やり方を調べました。
How to add placeHolder Text in UItextView? in iphone sdk [duplicate]
に詳細なプログラムが書いてあったので、そこで紹介されているプログラムを借用すれば基本的におk
//textViewは、UITextViewのインスタンス変数 - (BOOL) textViewShouldBeginEditing:(UITextView *)textView{ //PlaceHolderの色 UIColor placeHolderColor; //通常のテキストカラー UIColor textColor; if ([textView.textColor isEqual:placeHolderColor]) { textView.text = @""; textView.textColor = textColor; } return YES; }参照もとでは、UIColorを==で比較していましたが、クラス同士の比較なので、ここでは、isEqualメソッドを使いました。
dispatch_async内で、UITextViewのtextプロパティーにアクセスしたら下のような警告が出力された。
void _WebThreadLockFromAnyThread(bool), 0x8547fb0: Obtaining the web lock from a thread other than the main thread or the web thread. UIKit should not be called from a secondary thread. |
dispatch_async(main_queue, ^{ });の中だとおkなんだけど、
dispatch_async(dispatch_queue_create("hoge", NULL);, ^{ });の中だとNG.
NSString *foo = uiTextView.text; dispatch_async(dispatch_queue_create("hoge", NULL);, ^{ //fooを使った処理 });って書けばいいんですな。
Bootstrapベースのサイトでサイトの使い方をステップ別にオーバレイ表示できる「Bootstro.js」。
via:Bootstrapベースのサイトでサイトの使い方をステップ別にオーバレイ表示できる「Bootstro.js」
なんで、jQuery依存なのー。BootStrap好きなのにー。Bootstrapのテーマで良い感じに動くオートサジェスト実装jQueryプラグイン「MagicSuggest」
via:Bootstrapのテーマで良い感じに動くオートサジェスト実装jQueryプラグイン「MagicSuggest」
これなんか便利でよさげな感じ
どうやら、無料だし、各言語ごとの切り替えに伴うUIの変更も確認することができるようです。Android Studioは、Javaの統合開発環境として知られる「IntelliJ」をベースにしたAndroidアプリケーションの開発環境だと説明されました。
via:[速報]グーグル、Androidのための統合開発ツール「Android Studio」発表。オープンソースで無償提供。Google I/O 2013