Category Archives: IOS

「ios」iponeとandroidのバージョンを取得するサンプルコード

サンプルコード
– (void)viewDidLoad {
[super viewDidLoad];

NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
NSLog(@”–phoneVersion–%@—–“,phoneVersion);

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSLog(@”–infoDictionary–%@—–“,infoDictionary);

NSString *appCurVersion = [infoDictionary objectForKey:@”CFBundleShortVersionString”];
NSLog(@”–appCurVersion—%@—–“,appCurVersion);

「ios」UISearchBarの背景色を設定するコード

iosコード:
cftSearchBar.backgroundColor = RGBACOLOR(249,249,249,1);
cftSearchBar.backgroundImage = [self imageWithColor:[UIColor clearColor] size:cftSearchBar.bounds.size];

//earchbarの背景色をキャンセル
– (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;
}

「ios開発」グラフィックス関係Graphicsを利用するコード

1.RootViewController.h
#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController

@end
2.RootViewController.m
#import “RootViewController.h”

@interface RootViewController ()

@end

@implementation RootViewController

– (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

– (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

//背景画像
[self addView];

}

#pragma -mark -functions
//背景画像
-(void)addView
{
UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 44, 44)];
imageView.image=[self defaultImage];
[self.view addSubview:imageView];
}
//defaultImage画像
-(UIImage *)defaultImage {

static UIImage *defaultImage = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(20.f, 13.f), NO, 0.0f);

[[UIColor blackColor] setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 20, 1)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 5, 20, 1)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 10, 20, 1)] fill];

[[UIColor whiteColor] setFill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 1, 20, 2)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 6, 20, 2)] fill];
[[UIBezierPath bezierPathWithRect:CGRectMake(0, 11, 20, 2)] fill];

defaultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

});
return defaultImage;
}

– (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

「iOS開発」UIWebViewとWKWebViewの使い方

1.UIWebView
func getImage(context: ServiceExecuteContext) -> UIImage {
UIGraphicsBeginImageContextWithOptions(context.fromViewController.webView.bounds.size, true, 0)
context.fromViewController.webView.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

//let imagRef = CGImageCreateWithImageInRect((image?.CGImage)!, context.fromViewController.webView.bounds)
//let newImage = UIImage.init(CGImage: imagRef!)
//UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
return image!
}

2.WKWebView
func getImage(context: ServiceExecuteContext) -> UIImage {

UIGraphicsBeginImageContextWithOptions(context.fromViewController.webView.bounds.size, true, 0)
for subView: UIView in context.fromViewController.webView.subviews {
subView.drawViewHierarchyInRect(subView.bounds, afterScreenUpdates: true)
}
//UIApplication.sharedApplication().keyWindow?.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

//let imagRef = CGImageCreateWithImageInRect((image?.CGImage)!, context.fromViewController.webView.bounds)
//let newImage = UIImage.init(CGImage: imagRef!)

return image!
}

NSLogの出力フォーマットまとめ

char: %c
short int: %hi %hx %ho
unsigned short int: %hu %hx %ho %hu %hx %ho
int: %i %x %o
unsigned int: %u %x %o
long int: %li %lx %lo
unsigned long int: %lu %lx %lo
long long int: %lli %llx &llo
unsigned long long int: %llu %llx %llo
float: %f %e %g %a
double: %f %e %g %a
long double: %Lf $Le %Lg

「ios開発」CoreTelephonyでiphoneのキャリア情報を取得するコード

サンプルコード
#import CoreTelephony/CTTelephonyNetworkInfo.h
#import CoreTelephony/CTCarrier.h

CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netinfo subscriberCellularProvider];
NSLog(@”キャリア名: %@”, carrier.carrierName);

「iOS開発」CTCallCenterで通話の開始停止を検出するコード

サンプルコード
CTCallCenter *center = [[CTCallCenter alloc]init];
center_ = center;
center.callEventHandler = ^(CTCall *call){
NSLog(@”call:%@”,call.description);
if ([call.callState isEqualToString:@”CTCallStateDialing”]) {
//通話状態
}
if ([call.callState isEqualToString:@”CTCallStateDisconnected”]) {
//切断状態
}
};

「iOS入門」AFNetworkingのcookieリダイレクトを実装するコード

サンプルコード
BESTHttpItem *httpItem = [BESTHttpHelper sharedHelper].curHttpItem;
NSString *url = [NSString stringWithFormat:@”%@/#/login”, httpItem.frontend_addr];
// headerFieldsの取得
NSDictionary *headerFields = [NSHTTPCookie requestHeaderFieldsWithCookies:self.cookies];
// cookieアドレスを置換
[NSHTTPCookie cookiesWithResponseHeaderFields:headerFields forURL:[NSURL URLWithString:url]];

「IOS」Documentsのパスの取得方法

1.Documentsのパスの取得
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];

2.Cachesパスの取得
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];

3.tmpディレクトリの取得
NSString *tmpDir = NSTemporaryDirectory();

「mac」tomcat起動スクリプトを設定するメモ

$sudo chmod +x /usr/local/tomcat/bin/*.sh
$vi /usr/local/bin/tomcat
#!/bin/bash
case $1 in
start)
sh /usr/local/etc/tomcat/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/etc/tomcat/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/etc/tomcat/tomcat/bin/shutdown.sh
sh /usr/local/etc/tomcat/tomcat/bin/startup.sh
;;
*)
echo “Usage: start|stop|restart”
;;
esac

exit 0
$tomcat start
$tomcat stop
$tomcat restart

1 / 2212345...1020...最後 »