Skip to content

Instantly share code, notes, and snippets.

@yoshimin
yoshimin / gist:858d14751fc1c00807d2
Created August 10, 2014 17:06
NSAttributedStringを使ってリンク文字を作る
#import "YMNViewController.h"
NSString *const Text = @"The iOS Developer Program provides a complete and integrated process for developing and distributing iOS apps on the App Store. Learn more";
NSString *const LinkText = @"Learn more";
@interface YMNViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UITapGestureRecognizer *tapGesture;
@yoshimin
yoshimin / gist:670e2d551cb9afcd8cd4
Created September 17, 2014 16:48
AVPlayerで動画を再生
// サンプル動画のパスを取得
let bundle = NSBundle.mainBundle()
let url: NSURL = NSBundle.mainBundle().URLForResource("sample", withExtension: "mp4")!
// 動画のパスを指定してplayerItemを生成
self.playerItem = AVPlayerItem(URL: url)
// 上で生成したplayerItemを指定してplayerを生成
self.videoPlayer = AVPlayer(playerItem: self.playerItem)
@yoshimin
yoshimin / gist:8514127
Created January 20, 2014 02:53
UIButton+block.m
#import "UIButton+block.h"
#import <objc/runtime.h>
static char BUTTON_BLOCK;
@implementation UIButton (block)
- (void)addBlock:(void (^)(void))block forControlEvents:(UIControlEvents)event {
self.didTapped = block;
[self addTarget:self action:@selector(callBlock:) forControlEvents:event];
@yoshimin
yoshimin / gist:8514122
Created January 20, 2014 02:52
UIButton+block.h
#import <UIKit/UIKit.h>
@interface UIButton (block)
@property (nonatomic, copy) void (^didTapped)();
- (void)addBlock:(void (^)(void))block forControlEvents:(UIControlEvents)event;
@end
@yoshimin
yoshimin / gist:8254289
Last active January 2, 2016 04:59
基本的なNSAttributedStringの実装
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
label.font = [UIFont systemFontOfSize:10.f];
[self.view addSubview:label];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"UILabelにNSAttributedStringを表示〆(∀`*)"];
NSDictionary *attributes = @{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)}; // ここではアンダーラインをセット
[attrStr addAttributes:attributes range:NSMakeRange(0, attrStr.length)];
label.attributedText = attrStr;
@yoshimin
yoshimin / gist:6255401
Last active December 21, 2015 05:18
UILabelにCAGradientLayerをつかってグラデーションをかける
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
//レイヤをビューの中央に配置する
gradientLayer.bounds = self.layer.bounds;
gradientLayer.position = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
gradientLayer.startPoint = CGPointMake(0, CGRectGetMidY(self.frame)); //開始ポイント
gradientLayer.endPoint = CGPointMake(1, CGRectGetMidY(self.frame)); //終了ポイント
id opaque = (id)[UIColor blackColor].CGColor; //開始色
@yoshimin
yoshimin / gist:6060200
Created July 23, 2013 06:06
htmlでファイルをアップロード
<form enctype="multipart/form-data" action="アクション" method="post">
<input type="file" name="movie" /><br />
<br />
<input type="submit" value="送信" />
</form>
@yoshimin
yoshimin / gist:6060188
Last active December 20, 2015 02:59
PHPでPOSTで送信されたデータを受け取る処理
$updir = "./movies/";
$filename = $_FILES['movie']['name'];
//is_uploaded_file でファイルがアップロードされたかどうか調べる
if (is_uploaded_file($_FILES["movie"]["tmp_name"])) {
//move_uploaded_file を使って一時的な保存先から指定のフォルダに移動させる
if (move_uploaded_file($_FILES["movie"]["tmp_name"], $updir.$filename)) {
var_dump("成功");
@yoshimin
yoshimin / gist:6060096
Last active December 20, 2015 02:59
objective-cのNSMutableURLRequestを使ってファイルをアップロードする
#import "YSViewController.h"
@interface YSViewController ()
@end
@implementation YSViewController
- (void)viewDidLoad {
@yoshimin
yoshimin / gist:5954336
Last active December 19, 2015 12:19
UIAlertView+Block .mファイル UIAlertViewで、delegateではなくBlockを使ってボタンが押された時の処理を指定する
#import "UIAlertView+Block.h"
#import <objc/runtime.h>
static char CANCEL_BUTTON_BLOCK;
static char OTHER_BUTTON_BLOCK;
@implementation UIAlertView (Block)
+ (UIAlertView*)alertViewWithTitle:(NSString *)title
message:(NSString *)message