快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

收集的常用有用代码-创新互联

* 给导航条加阴影

凉州网站建设公司创新互联公司,凉州网站设计制作,有大型网站制作公司丰富经验。已为凉州成百上千家提供企业网站建设服务。企业网站搭建\成都外贸网站建设要多少钱,请找那个售后服务好的凉州做网站的公司定做!
if ([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
        [[UINavigationBar appearance] setBackgroundImage:[UIImage p_w_picpathNamed:@"head"] forBarMetrics:UIBarMetricsDefault];
        self.navigationBar.layer.masksToBounds = NO;
        //设置阴影的高度
        self.navigationBar.layer.shadowOffset = CGSizeMake(0, 3);
        //设置透明度
        self.navigationBar.layer.shadowOpacity = 0.6;
        self.navigationBar.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.navigationBar.bounds].CGPath;
    }


12.键盘透明

textField.keyboardAppearance = UIKeyboardAppearanceAlert;

状态栏的网络活动风火轮是否旋转

[UIApplication sharedApplication].networkActivityIndicatorVisible,默认值是NO。

13.截取屏幕图片

//创建一个基于位图的图形上下文并指定大小为CGSizeMake(200,400)

UIGraphicsBeginImageContext(CGSizeMake(200,400));

//renderInContext 呈现接受者及其子范围到指定的上下文

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

//返回一个基于当前图形上下文的图片

UIImage *aImage = UIGraphicsGetImageFromCurrentImageContext();

//移除栈顶的基于当前位图的图形上下文

UIGraphicsEndImageContext();

//以png格式返回指定图片的数据

p_w_picpathData = UIImagePNGRepresentation(aImage);

14.更改cell选中的背景

UIView *myview = [[UIView alloc] init];

myview.frame = CGRectMake(0, 0, 320, 47);

myview.backgroundColor = [UIColorcolorWithPatternImage:[UIImage p_w_picpathNamed:@"0006.png"]];

cell.selectedBackgroundView = myview;

2.图片压缩

用法:UIImage *yourImage= [self p_w_picpathWithImageSimple:p_w_picpath scaledToSize:CGSizeMake(210.0, 210.0)];

//压缩图片

- (UIImage*)p_w_picpathWithImageSimple:(UIImage*)p_w_picpath scaledToSize:(CGSize)newSize

{

// Create a graphics p_w_picpath context

UIGraphicsBeginImageContext(newSize);

// Tell the old p_w_picpath to draw in this newcontext, with the desired

// new size

[p_w_picpath drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

// Get the new p_w_picpath from the context

UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();

// End the context

UIGraphicsEndImageContext();

// Return the new p_w_picpath.

return newImage;

}

3.亲测可用的图片上传代码

- (IBAction)uploadButton:(id)sender {

UIImage *p_w_picpath = [UIImage p_w_picpathNamed:@"1.jpg"]; //图片名

NSData *p_w_picpathData = UIImageJPEGRepresentation(p_w_picpath,0.5);//压缩比例

NSLog(@"字节数:%i",[p_w_picpathData length]);

// post url

NSString *urlString = @"http://192.168.1.113:8090/text/UploadServlet";

//服务器地址

// setting up the request object now

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;

[request setURL:[NSURL URLWithString:urlString]];

[request setHTTPMethod:@"POST"];

//

NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data;boundary=%@",boundary];

[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

//

NSMutableData *body = [NSMutableData data];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString  stringWithString:@"Content-Disposition:form-data; name=\"userfile\";  filename=\"2.png\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];  //上传上去的图片名字

[body appendData:[[NSString stringWithString:@"Content-Type:  application/octet-stream\r\n\r\n"]  dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[NSData dataWithData:p_w_picpathData]];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:body];

// NSLog(@"1-body:%@",body);

NSLog(@"2-request:%@",request);

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(@"3-测试输出:%@",returnString);

iOS开发之UIlabel多行文字自动换行 (自动折行)

UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, 300, 180)];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 150)];

label.text = @"Hello world! Hello world!Hello world! Hello world!  Hello world! Hello world! Hello world! Hello world!Hello world! Hello  world! Hello world! Hello world! Hello world! Helloworld!";

//背景颜色为红色

label.backgroundColor = [UIColor redColor];

//设置字体颜色为白色

label.textColor = [UIColor whiteColor];

//文字居中显示

label.textAlignment = UITextAlignmentCenter;

//自动折行设置

label.lineBreakMode = UILineBreakModeWordWrap;

label.numberOfLines = 0;

3、在程序中播放声音:

首先在程序添加AudioToolbox:

收集的常用有用代码

其次,在有播放声音方法的.m方法添加#import:

#import

接下来,播放声音的代码如下:

NSString *path = [[NSBundle mainBundle] pathForResource:@"soundFileName" ofType:@"wav"];

SystemSoundID soundID;

AudioServicesCreateSystemSoundID ((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);

AudioServicesPlaySystemSound (soundID);

7、捕捉程序关闭或者进入后台事件:

UIApplication *app = [UIApplication sharedApplication];

[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(applicationWillResignActive:)  name:UIApplicationWillResignActiveNotification object:app];

applicationWillResignActive:这个方法中添加想要的操作

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站题目:收集的常用有用代码-创新互联
分享链接:http://6mz.cn/article/dscjid.html

其他资讯