IOS用戶端Coding項目記錄(三),ios用戶端coding項目

來源:互聯網
上載者:User

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=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;}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.