随笔分类 - iPhone开发
不积跬步,无以至千里。
摘要:方法一:通过View的中心位置来移动-(BOOL)textFieldShouldReturn:(id)sender{ self.view.center=CGPointMake(160,207); [sender resignFirstResponder]; return YES;}- (BOOL)textFieldShouldBeginEditing:(id)sender{ UITextField *textField = (UITextField *)sender; if(textField.tag==1) { self.view.ce...
阅读全文
摘要:UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(125, 50, 229, 229)]; [imageview1 setImage:[UIImage imageWithContentsOfFile:path]]; imageview1.userInteractionEnabled = YES; UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWi...
阅读全文
摘要:UIView设置背景图片可以使用如下代码: self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"dula.png"]];但是,这段代码存在一个危险。alloc和init一个对象后,count就会加1,这时需要调用release方法来释放内存。设置UIView背景图片更为保险的方法是:self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"
阅读全文
摘要:iPhone系统的字体数量有限,并且多数对中文没有效果,下面介绍两种解决办法方法1: 添加对应的字体(.ttf或.odf)到工程的resurce,使用cocos2d中的FontLabel库,FontLabel继承于UILabel,象UILabel一样使用就好了 fontName直接使用添加的资源名字即可方法2; 1,添加对应的字体(.ttf或.odf)到工程的resurce,例如simkai.ttf 2,在info.plist中添加一项 Fonts provided by application (item0对应的value为simkai.ttf,添加多个字体依次添加就可以了) 3,...
阅读全文
摘要:将UIView的最初位置置为窗口之外,然后通过一个动画来实现UIView的飞入效果,固定好进入的位置。 [newvision setFrame:CGRectMake(-200,30,175,145)]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDuration:1]; //动画时长 [newvision setFrame:CGRectMake(5,30,175,14...
阅读全文
摘要:用UIImage加载图像的方法很多,最常用的是下面三种:一、用imageNamed函数引用[UIImage imageNamed:ImageName];二、用NSData的方式加载NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:extension]; NSData *image = [NSData dataWithContentsOfFile:filePath]; [UIImage imageWithData:image];三,使用[UIImage imageWithContentOfFil
阅读全文
摘要:1、引入头文件#include <sys/sysctl.h>#include <mach/mach.h>2、检测函数//MARK: 可用内存- (double)availableMemory{ vm_statistics_data_t vmStats; mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT; kern_return_t kernReturn = host_statistics(mach_host_self(),HOST_VM_INFO,(host_info_t)&vmStats,&in
阅读全文
摘要:iPhone程序发布的时候应该会用到下面这些图标,大小和用途如下:图片大小(px)文件名用途重要程度512X512iTunesArtworkiTunes商店上展示可以没有,推荐有57X57Icon.pngiPhone/iPod touch上的App Store以及Home界面这个必须要有114X114Icon@2x.pngiPhone 4(高分辨率)的Home 界面可以没有,推荐有72x72Icon-72.png兼容iPad的Home界面可以没有,推荐有29x29Icon-Small.pngSpotlight搜索以及设置界面可以没有,推荐有50x50Icon-Small-50.png兼容iPa
阅读全文
摘要:一、静态图片的设置iOS设备现在有三种不同的分辨率:iPhone 320x480、iPhone 4 640x960、iPad 768x1024。以前程序的启动画面(图片)只要准备一个 Default.png 就可以了,但是现在变得复杂多了。下面就是 CocoaChina 会员做得总结 如果一个程序,既支持iPhone又支持iPad,那么它需要包含下面几个图片:Default-Portrait.png iPad专用竖向启动画面 768x1024或者768x1004Default-Landscape.png iPad专用横向启动画面 1024x768或者1024x748Default-Portra
阅读全文
摘要:如果要移除一个 UIView 的所有子视图,SDK 里没有 remove all 之类的方法。可以用 for loop 循环调用 – removeFromSuperview 来移除 例如:for(UIView *view in [self.view subviews]){ [view removefromsuperview];}如果要移动指定的视图,可以这样: for(UIView *mylabelview in [self.view subviews]) { if ([mylabelview isKindOfClass:[UILabel class]]) { ...
阅读全文
摘要:上下划动可以用类似的方法实现:#import <UIKit/UIKit.h>@interface Abstruct : UIViewController <UIScrollViewDelegate>{ UIImageView* myimageview; NSMutableArray *imgArray; CGPoint FirstPoint; CGPoint SecondPoint; NSInteger Page; BOOL touchMove;}@property (retain, nonatomic) UIImageView* myimageview;...
阅读全文
摘要:MPMoviePlayerViewController用于播放视频,用法如下:NSBundle *bundle = [NSBundle mainBundle];NSString *moviePath = [bundle pathForResource:@"movie" ofType:@"mp4"];NSURL *movieURL = [NSURL fileURLWithPath:moviePath];MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewCo
阅读全文
摘要:一、始终隐藏状态栏如果在App中需要状态栏一直是隐藏着的,可以在<YOUR_APP>AppDelegate的application:didFinishLaunchingWithOptions:函数中进行设置,比如下面这段示意代码可以让状态栏以淡出的方式隐藏起来:- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after applicatio
阅读全文
摘要:每隔段时间执行相应的操作://时间间隔,每隔5秒执行handleMaxShowTimer NSTimeInterval timeInterval =5.0 ; //定时器 NSTimer *showTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self s...
阅读全文
摘要:一、UITableView的最基本使用实现协议UITableViewDelegate,UITableViewDataSource的下述方法://设置表的分区数- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView { return 1; }//设置每个区的行数- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section { return [UIFont familyNames].coun...
阅读全文
摘要:一、UILabel的多行显示问题1.N行完全自适应: UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 100, 21)]; NSString *txt = @"dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; testLabel.numberOfLines = 0; ///相当于不限制行数 testLabel.text = txt;
阅读全文
摘要:参考来自:http://zhiwei.li/text/2011/07/iphone%E4%B8%8Aaes%E5%8A%A0%E5%AF%86%E7%9A%84%E5%AE%9E%E7%8E%B0/头文件 NSDataEncryption.h#import <UIKit/UIKit.h>@interface NSData (AES256)- (NSData *)AES256EncryptWithKey:(NSString *)key;//加密- (NSData *)AES256DecryptWithKey:(NSString *)key;//解密@end实现 NSDataEncry
阅读全文
摘要:引入头文件:#import <CommonCrypto/CommonDigest.h>加密算法://TODO: md5 加密方法- (NSString*)md5Digest:(NSString *)str{ //32位MD5小写 const char *cStr = [str UTF8String]; unsigned char result[32]; CC_MD5( cStr, strlen(cStr), result ); return [NSString stringWithFormat: ...
阅读全文
摘要:首先实现UIScrollViewDelegate协议:#import <UIKit/UIKit.h>@interface Activity01ViewController : UIViewController<UIScrollViewDelegate>{ UIScrollView *myscrollview;}@property (nonatomic,retain) UIScrollView *myscrollview;@end实现协议的下列方法:#import <UIKit/UIKit.h>@interface Activity01ViewControll
阅读全文
摘要:参考来自:http://www.cocoachina.com/iphonedev/sdk/2011/0525/2885.html下面是.h文件的代码//// EGORefreshTableHeaderView.h// Demo//// Created by Devin Doty on 10/14/09October14.// Copyright 2009 enormego. All rights reserved.//#import <UIKit/UIKit.h>#import <QuartzCore/QuartzCore.h>typedef enum{ EGOOPul
阅读全文

浙公网安备 33010602011771号