当然如果你的项目大的话最好使用开源的网络库ASI或者AFNetWork,库里面都有现有的方法, 如果你觉得就是想自己写一个,看这里 - (NSMutableURLRequest *)PostImageRequest:(NSString *)URLString UIImage:(UIImage*)image
如果你的工程里面是用的AFNetworking请求网络数据的话,那么可以直接使用 AFNetworkReachabilityManager.h来判断网络状态!如果是用的ASI的话,里面自带的有Reachability.m和 Reachability.h这两个类,下面会分开介绍这两个的使用方法。 使用AF请求网络: 在AppDelegate.h里面添加类方法: + (void)netWorkStat
1.导入库文件:MessageUI.framework 2.引入头文件 3.实现代理< MFMailComposeViewControllerDelegate > 和 < UINavigationControllerDelegate > @代码示例: - (void)didClickSendEmailButtonAction{ if ([MFMailComposeViewController ca
@import Darwin.sys.mount; int main(int argc, char * argv[]) { @autoreleasepool { struct statfs buf; long long freespace = 0; if (statfs("/", &buf) >= 0) { freespace = (long long)buf.f_bsize * buf.f_bl
一、不可变字符 NSString是不可变字符串,它产生的其他字符串方法都是生成一个新的字符串,而不会改变原来字符串。 1.创建方式 //1)字面量,它是常量字符串,存储常量区 NSString *str=@"hello"; //2)通过快捷构造法,存储堆区 NSString *str = [NSString stringWithFormat:@"hello %@", @"world"]; //3)
直接上代码。 NSString+Estimat.h #import <Foundation/Foundation.h> @interface NSString (Estimate) + (BOOL)isNotBlank:(NSString*)source; + (BOOL)isBlank:(NSString*)source; //正整数验证(带0). +(BOOL) isPositiveNum:(
在 AppDelegate.m中添加如下代码: -(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ return UIInterfaceOrientationMaskPortrait;
- (void) turnTorchOn: (bool) on { Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice"); if (captureDeviceClass != nil) { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaTy
UIWebView加载Loading...两种方法 第一种方法:使用UIView and UIActivityIndicatorView //创建UIWebView WebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)]; [WebView setUserInteractionEnabled:NO]; [Web
/* *点击获取prodcut实例并初始化订单信息 */ Product*product = [[Product alloc] init]; product.subject=@"机票"; product.body=@"乘客机票"; product.price=0.01f; /* *商户的唯一的parnter和seller。 *签约后,支付宝会为每个商户分配一个唯一的parnter和seller。
当提供的图片是100宽 而内容是200宽时 会显示的内容 超出图片长度的情况。 直接上解决方案。 _reserveLabel.text = @"1234567890"; //获取Label内容长度 CGSize reserveLabelSize = [_reserveLabel sizeThatFits:CGSizeMake(MAXFLOAT, 32)]; //重设Label的frame _re
1、同步请求可以从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作, 2、异步请求不会阻塞主线程,而会建立一个新的线程来操作,用户发出异步请求后,依然可以对UI进行操作,程序可以继续运行 3、GET请求,将参数直接写在访问路径上。操作简单,不过容易被外界看到,安全性不高,地址最多255字节; 4、POST请求,将参数放到body里面。POST请求操
// NSString* timeStr = [self stringWithDate: [NSDate dateWithTimeIntervalSince1970:userGifGrouptEntity.lastGiftSentTime / 1000]] - (NSString *)stringWithDate:(NSDate *)date { if (date == nil) return @
项目里面需要实现,点击webView里面的图片,看大图并且能够放大缩小效果,在此记录下实现过程。 在webViewDelegate里面添加如下代码: - (void)webViewDidFinishLoad:(UIWebView *)aWebView { //调整字号 NSString *str = @"document.getElementsByTagName('body')[0
有的时候 app的启动页会一闪而过,如果想让启动页画面停留一会再启动应用 可以使用如下方式 在AppDelegate的方法 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //添加如下方法 将主线程暂停几秒钟 [NSThrea
@interface IWViewController () @end @implementation IWViewController - (void)viewDidLoad { [super viewDidLoad]; for (int i = 0; i<9; i++) { NSString *file = [NSString stringWithFormat:@"/Users/aplle/D
- (IBAction)openFlash:(id)sender { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if ([device hasTorch] && [device hasFlash]) { [device lockForConfiguration:n
// // main.m // Bus-公交 /* 公交一卡通充值系统,有两种功能选择,第一种投入硬币或者纸币 选择购票,第二种一卡通充值,充值面额是20,50,100 */ #import <Foundation/Foundation.h> #import "Card.h" #import "ChargeMachine.h" #import "Money.h" int main(int argc
在这里首先明确,View中显示的东西都在在layer中的。 我们通过renderInContext来渲染layer中的内容 - (void)viewDidLoad { [super viewDidLoad]; //截取当前的View //1.创建图层 UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0); //2
URL特殊字符处理 一般来说我们调用webVIew的时候,只要给webVIew传一个url,在网页里面就可以显示网页信息。但是当我们传的url比较麻烦或者带文字符,带参数的时候我们需要对特殊字符进行转义。我们还可以用遍历,正则等来把特殊字符给替换掉!! 有两种方法: 一,使用NSString的方法: 1. //字符串加百分号转义使用编码 (这个方法会把参数里面的东西转义) NSString *st