首页 > 代码库 > IOS客户端Coding项目记录(三)

IOS客户端Coding项目记录(三)

18:图片视图几种填充样式

_imgView.contentMode = UIViewContentModeScaleAspectFill;如下:typedef NS_ENUM(NSInteger, UIViewContentMode) {    UIViewContentModeScaleToFill,    UIViewContentModeScaleAspectFit,        UIViewContentModeScaleAspectFill,       UIViewContentModeRedraw,              // redraw on bounds change (calls -setNeedsDisplay)    UIViewContentModeCenter,              // contents remain same size. positioned adjusted.    UIViewContentModeTop,    UIViewContentModeBottom,    UIViewContentModeLeft,    UIViewContentModeRight,    UIViewContentModeTopLeft,    UIViewContentModeTopRight,    UIViewContentModeBottomLeft,    UIViewContentModeBottomRight,};简单说明:UIViewContentModeScaleToFill:表示完全填充在 frame. 里。(默认)UIViewContentModeScaleAspectFit:保持比例,都在 frame. 内。UIViewContentModeScaleAspectFill:保持比例,填满但 frame. 外也有。UIViewContentModeRedraw:?   UIViewContentModeCenter:这个 image 的中心与 frame. 的中心重合。UIViewContentModeTop:这个 image 的上边缘与 frame. 的上边缘重合。UIViewContentModeBottom:这个 image 的下边缘与 frame. 的下边缘重合。UIViewContentModeLeft:这个 image 的左边缘与 frame. 的左边缘重合。UIViewContentModeRight:这个 image 的右边缘与 frame. 的右边缘重合。UIViewContentModeTopLeft:类似。UIViewContentModeTopRight:类似。UIViewContentModeBottomLeft:类似。UIViewContentModeBottomRight:类似。

19:UIView属性clipsTobounds的应用

view添加view,并剪边(UIView属性clipsTobounds的应用)如题,有两个view: view1,view2view1添加view2到其中,如果view2大于view1,或者view2的坐标不在view1的范围内,view2是盖着view1的,意思就是超出的部份也会画出来UIView有一个属性,clipsTobounds 默认情况下是NO,如果,我们想要view2把超出的那部份隐藏起来的话,就得改变它的父视图也就view1的clipsTobounds属性值。view1.clipsTobounds = YES;

20:CALayer常见几个设置

边框,圆角,阴影设置圆角边框?someView.layer.cornerRadius =4.0f;someView.layer.masksToBounds = YES;//设置边框及边框颜色?someView.layer.borderWidth = 0.5f;someView.layer.borderColor =[ [UIColor grayColor] CGColor];?//添加四个边阴影? _imgvPhoto.layer.shadowColor = [UIColor blackColor].CGColor;? _imgvPhoto.layer.shadowOffset = CGSizeMake(0, 0);?  _imgvPhoto.layer.shadowOpacity = 0.5;? _imgvPhoto.layer.shadowRadius = 10.0; _ imgvPhoto.layer.masksToBounds = NO;  //添加两个边阴影?    _imgvPhoto.layer.shadowColor = [UIColor blackColor].CGColor;?    _imgvPhoto.layer.shadowOffset = CGSizeMake(4, 4);?    _imgvPhoto.layer.shadowOpacity = 0.5;?    _imgvPhoto.layer.shadowRadius = 2.0;说明:?①     someView  表示UIView及其之类;?②     必须引入:#import<QuartzCore/QuartzCore.h>

21:UIActionSheet弹出显示

#define kKeyWindow [UIApplication sharedApplication].keyWindowUIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相册选择", nil];[actionSheet showInView:kKeyWindow];

22:block回调传参的运用

有两个viewcontroller分别为a,b;其中a跳转到b,从b得到一个值,然后再跳转到a,并显示出b的值;代码如下:a.h- (IBAction)otherStoryboard:(id)sender;@property (weak, nonatomic) IBOutlet UILabel *lableInfo;a.m- (IBAction)otherStoryboard:(id)sender {    UIStoryboard* mainStoryboard=[UIStoryboard storyboardWithName:@"HotelStoryboard" bundle:nil];    HotelViewController* weathcontroller=[mainStoryboard instantiateViewControllerWithIdentifier:@"hotelStoryboard"];    weathcontroller.block=^(NSString* InputValue)    {        self.lableInfo.text=InputValue;    };    [self presentViewController:weathcontroller animated:YES completion:^{            }];}b.htypedef void(^ChangInputText)(NSString* InputValue);@property(copy,nonatomic)ChangInputText block;- (IBAction)backButton:(id)sender;@property (weak, nonatomic) IBOutlet UITextField *inputText;b.m- (IBAction)backButton:(id)sender {    NSString* backsValue=http://www.mamicode.com/self.inputText.text;    _block(backsValue);    [self dismissViewControllerAnimated:YES completion:^{            }];}当然也可以使用一个公开的方法,然后把block伟参数直接调用,可以访问下面的网址:http://blog.csdn.net/itpeng523/article/details/24315541

23:单例模式运用

.h@interface Coding_NetAPIManager : NSObject(instancetype)sharedManager;- (void)request_Tweet_DoTweet_WithObj:(Tweet *)tweet andBlock:(void (^)(id data, NSError *error))block;@end.m@implementation Coding_NetAPIManager+ (instancetype)sharedManager {    static Coding_NetAPIManager *shared_manager = nil;    static dispatch_once_t pred;    dispatch_once(&pred, ^{        shared_manager = [[self alloc] init];    });    return shared_manager;}(void)request_Tweet_DoTweet_WithObj:(Tweet *)tweet andBlock:(void (^)(id data, NSError *error))block{    ….   }@end然后调用时:        [[Coding_NetAPIManager sharedManager] request_Tweet_DoTweet_WithObj:nextTweet andBlock:^(id data, NSError *error) {        }];

24:常见的常量

#define kKeyWindow [UIApplication sharedApplication].keyWindow#define kScreen_Bounds [UIScreen mainScreen].bounds#define kScreen_Height [UIScreen mainScreen].bounds.size.height#define kScreen_Width [UIScreen mainScreen].bounds.size.width常用的方法:- (void)setY:(CGFloat)y{    CGRect frame = self.frame;    frame.origin.y = y;    self.frame = frame;}- (void)setX:(CGFloat)x{    CGRect frame = self.frame;    frame.origin.x = x;    self.frame = frame;}- (void)setHeight:(CGFloat)height{    CGRect frame = self.frame;    frame.size.height = height;    self.frame = frame;}- (void)setWidth:(CGFloat)width{    CGRect frame = self.frame;    frame.size.width = width;    self.frame = frame;}- (void)setSize:(CGSize)size{    CGRect frame = self.frame;    frame.size.width = size.width;    frame.size.height = size.height;    self.frame = frame;}+ (CGRect)frameWithOutNavTab{    CGRect frame = kScreen_Bounds;    frame.size.height -= (20+44+49);//减去状态栏、导航栏、Tab栏的高度    return frame;}+ (CGRect)frameWithOutNav{    CGRect frame = kScreen_Bounds;    frame.size.height -= (20+44);//减去状态栏、导航栏的高度    return frame;}

 

IOS客户端Coding项目记录(三)