CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = self.view.bounds; gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor redColor] CGColor], (id)[[UIColor whiteColor] CGColor]
原文 http://www.jianshu.com/p/f6587baafb3c 最近有一些比较流行的应用,界面都是圆角的。比如Memopad,Pinterest之类的,都是。 琢磨了一下,发现这个其实很简单。我们只需要在UIView上做点功夫就可以了。 创建一个UIView的Category,名为 UIView+RoundCorner ,在头文件 UIView+RoundCorner.h 中声明
在tableView的右边搜索,尤其是电话薄经常使用汉字的首字母.但是NSString只能获取字母字符串的首字母. #import "pinyin.h" NSString *hanyu = @"程序员"; for (int i = 0; i < [hanyu length]; i++) { printf("%c", pinyinFirstLetter([hanyu characterAtIndex
//在此之前要遵守协议<NSURLConnectionDataDelegate> #import "ViewController.h" #import "Cricl.h" @interface ViewController (){ UITextField *_textField; UIProgressView *_progressView; UILabel *_label; UIButton *_
//判断是否允许使用麦克风7.0新增的方法requestRecordPermission -(BOOL)canRecord { __block BOOL bCanRecord = YES; if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending) {
UINavigationBar *navigationBar = self.navigationController.navigationBar;// white.png图片自己下载个纯白色的色块,或者自己ps做一个 [navigationBar setBackgroundImage:[UIImage imageNamed:@"white.png"] forBarPosition:UIBarPos
+ (void)createFolder:(NSString *)folderName { NSString *imageDir = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(),folderName]; NSLog(@"HomeDir: %@",imageDir); BOOL isDir = NO; NSFile
#pragma mark - BMKMapViewDelegate // 根据anntation生成对应的View - (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation { //普通annotation NSString *AnnotationVie
#import <Foundation/Foundation.h> typedef enum { IdentifierTypeKnown = 0, IdentifierTypeZipCode, //1 IdentifierTypeEmail, //2 IdentifierTypePhone, //3 IdentifierTypeUnicomPhone, //4 IdentifierTypeQQ,
使用sqlite可以实现简单的收藏夹功能,不多说直接上代码。 1.首先导入libsqlite3.0.dylib,libz.dylib两个类库 2.封装一个NSObject类型的类去管理 (即写sql语句) 在这个类里首先导入一个头文件和你建好的model类 (实现收藏本质是存model类) model类只是建立需要的字符串(我只写了.h .m里什么都没写) #import <Foundation/
textField/textView收起键盘的方法有很多,但总的来说就是释放第一响应者和结束编辑即可 1.最简单粗暴的,只要在 任何 UIView子类结束编辑即可: 在一个VIewController收起键盘的方法如下: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:Y
#import "ViewController.h" #import <AddressBookUI/AddressBookUI.h> @interface ViewController ()<ABPeoplePickerNavigationControllerDelegate> @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @en
一:正则表达式再用 #pragma 正则匹配手机号 + (BOOL)checkTelNumber:(NSString *) telNumber { NSString *pattern = @^ 1 +[ 3578 ]+\d{ 9 }; NSPredicate *pred = [NSPredicate predicateWithFormat: @SELF MATCHES %@, pattern];
//需要真机 #import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface ViewController ()<AVCaptureMetadataOutputObjectsDelegate>//用于处理采集信息的代理 { AVCaptureSession * session;//输入输出的中间桥梁 }
网络编程---将网络上的大文件下载到本地,并打印其进度。 点击“开始传输”按钮,将网络上的大文件先下载下来,下载完成后,保存到本地。 UI效果图如下: 具体代码如下: // ViewController.m // 0611---数据请求+滚动条 #import "ViewController.h" unsigned long tempLength; @interface ViewControl
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"%@",NSHomeDirectory()); UIButton *button = [UIButton butt
在实际开发过程中,经常会遇到些不能让用户随便地输入手机号码,对输入的手机号码的正确判断;有些输入框只能输入数字,不能输入字母或特殊字符;还有些如价格金额之类的就只能输入数字和小数点且小数点后面保留两位。 ///// 手机号码的有效性判断 //检测是否是手机号码 - (BOOL)isMobileNumber:(NSString *)mobileNum { /** * 手机号码 * 移动:134[0-
//检查前后摄像头 - (void)cameraBtnAction:(id)sender { BOOL cameraAvailable = [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceRear];//前 BOOL frontCameraAvailable = [UIImag
//邮箱 + (BOOL) validateEmail:(NSString *)email { NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@"
返回x分钟前/x小时前/昨天/x天前/x个月前/x年前 - (NSString *)timeInfo { return [NSDate timeInfoWithDate:self]; } + (NSString *)timeInfoWithDate:(NSDate *)date { return [self timeInfoWithDateString:[self stringWithDate:d