有用的小代码

文章描述:-2022年2月19日发(作者:网站漏洞检测软件)常用代码整理: 12.判断邮箱格式是否正确的代码: 利用正则表达式验证 -(BOOL)isValidateEmail:(SString *)email { SString *emailRegex = @SPredicate *emailTest = [SPredicate predicateWithFormat:@return [email

-

有用的小代码 2022年2月19日发(作者:网站漏洞检测软件)


常用代码整理:
12.判断邮箱格式是否正确的代码:
利用正则表达式验证
-(BOOL)isValidateEmail:(SString *)email
{
SString *emailRegex = @
SPredicate *emailTest = [SPredicate predicateWithFormat:@
return [emailTest evaluateWithObject:email];
}
13.图片压缩
用法:UIImage *yourImage= [self imageWithImageSimple:image scaledToSize:CGSizeMake(210.0, 210.0)];
压缩图片
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize
{
Create a graphics image context
UIGraphicsBeginImageContext(newSize);
Tell the old image to draw in this newcontext, with the desired
new size
[image drawInRect:CGRectMake(0,0,,)];
Get the new image from the context
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
End the context
UIGraphicsEndImageContext();
Return the new image.
return newImage;
}
14.亲测可用的图片上传代码
- (IBAction)uploadButton:(id)sender {
UIImage *image = [UIImage imageamed:@图片名
SData *imageData = UIImageJPEGRepresentation(image,0.5);压缩比例
SLog(@字节数:%i
post url
SString *urlString = @
服务器地址
setting up the request object now
SMutableURLRequest *request = [[SMutableURLRequest alloc] init] ;
[request setURL:[SURL URLWithString:urlString]];
[request setHTTPMethod:@

SString *boundary =
[SString stringWithString:@
酥油灯厂家http:,压铆机http:


SString *contentType =
[SString stringWithFormat:@
[request addValue:contentType forHTTPHeaderField: @

SMutableData *body = [SMutableData data];
[body appendData:[[SString stringWithFormat:@
StringEncoding]];
[body appendData:[[SString stringWithString:@
filename=上传上去的图片名字
[body appendData:[[SString stringWithString:@
applicationoctet-streamrnrn
[body appendData:[SData dataWithData:imageData]];
[body appendData:[[SString stringWithFormat:@
F8StringEncoding]];
[request setHTTPBody:body];
SLog(@
SLog(@
SData *returnData =
[SURLConnection sendSynchronousRequest:requestreturningRespe:nil error:nil];
SString *returnString = [[SString alloc] initWithData:returnDataencoding:SUTF8StringEncoding];
SLog(@测试输出:%@
15.给imageView加载图片
UIImage *myImage = [UIImage imageamed:@
[imageView setImage:myImage];
[ addSubview:imageView];
16.对图库的操作
选择相册:
UIImagePickerControllerSourceTypesourceType=UIImagePickerControllerSourceTypeCamera;
if (![UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
}
UIImagePickerController * picker = [[UIImagePickerControlleralloc]init];
te = self;
Editing=YES;
Type=sourceType;
[self presentModalViewController:picker animated:YES];
选择完毕:
-(void)imagePickerController:(UIImagePickerController*)pickerdidFinishPickingMediaWithInfo:(SDiction
ary *)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage * image=[info objectForKey:UIImagePickerControllerEditedImage];
酥油灯厂家http:,压铆机http:


[self performSelector:@selector(selectPic:) withObject:imageafterDelay:0.1];
}
-(void)selectPic:(UIImage*)image
{
SLog(@
imageView = [[UIImageView alloc] initWithImage:image];
= CGRectMake(0, 0, , );
[dSubview:imageView];
[self performSelectorInBackground:@selector(detect:) withObject:nil];
}
detect为自己定义的方法,编辑选取照片后要实现的效果
取消选择:
-(void)imagePickerControllerDIdCancel:(UIImagePickerController*)picker

{
[picker dismissModalViewControllerAnimated:YES];
}
17.跳到下个View
nextWebView = [[WEBViewController alloc]initWithibame:@
[self presentModalViewController:nextWebView animated:YES];




创建一个UIBarButtonItem右边按钮
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@右边

[tionItem setRightBarButtonItem:rightButton];
设置navigationBar隐藏
tionBarHidden = YES;
iOS开发之UIlabel多行文字自动换行 (自动折行)
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(10, 100, 300, 180)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 150)];
= @
Hello world!Hello world! Hello world! Hello world! Hello world! Hello world! Helloworld!
背景颜为红
oundColor = [UIColor redColor];
设置字体颜为白
lor = [UIColor whiteColor];
文字居中显示
ignment = UITextAlignmentCenter;
自动折行设置
酥油灯厂家http:,压铆机http:

-

有用的小代码

发布时间:2022-02-19 01:27:48
文章版权声明:除非注明,否则均为IT技术网-学习WEB前端开发等IT技术的网络平台原创文章,转载或复制请以超链接形式并注明出处。

发表评论

评论列表 (有 7 条评论,277人围观)

最近发表

随便看看

热门文章

标签列表