IOS——雜集

來源:互聯網
上載者:User

標籤:

1、在UIView的子類中在視圖即將顯示的時候再次改變控制項的位置
- (void)layoutSubviews
{
[super layoutSubviews];

CGRect rect = _msgButton.frame;
rect.size.height = self.bounds.size.height -2*RMarginSize ;
_msgButton.frame = rect;
}

 

2、多少時間後執行再什麼
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  [hud dismiss];
});

3、獲得登陸資料

NSString *loginDataPath = [NSHomeDirectory() stringByAppendingString:@"/Documents/login.data"];
NSData *loginData = [NSData dataWithContentsOfFile:loginDataPath];
NSDictionary *loginDataDic = [NSJSONSerialization JSONObjectWithData:loginData options:0 error:nil];

 

4、 擷取字串的寬度或高度

self.width = [self.taskNameLab.text boundingRectWithSize:CGSizeMake(200, 44) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]} context:nil].size.width;

5、因為一般為了不讓UIview的背景色不延伸到 navigationBar 下面

self.navigationController.navigationBar.translucent = NO;
或者
 if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]){
 self.edgesForExtendedLayout = UIRectEdgeNone;
 }

 

6、鍵盤處理

#pragma 文字框委託方法

//當textField 開始編輯時調用的方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
float offset = self.view.frame.size.height - (_Bottomview.frame.origin.y + _Bottomview.frame.size.height + 216 +40);
NSLog(@"offset = %lf",offset);
if (offset <= 0) {
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.view.frame;
frame.origin.y = offset;
self.view.frame = frame;
}];
}
return YES;
}
//當textField 結束編輯時調用的方法
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.view.frame;
frame.origin.y = 0.0;
self.view.frame = frame;
}];
return YES;
}
//按下Done按鈕的調用方法,我們讓鍵盤消失

-(BOOL)textFieldShouldReturn:(UITextField *)textField {
NSString *info = _message.text;
NSLog(@"info = %@",info);
[textField resignFirstResponder];
return YES;
}
// 點擊頁面空白出 收取鍵盤
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

[super touchesBegan:touches withEvent:event];

// [self.view endEditing:YES]; // 點擊控制器View的地區會使得其他控制項放棄第一響應者身份。

[textField resignFirstResponder];
}

 7、定義宏,判斷ios7

#define IOS7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0
//添加代碼
if (IOS7)
{
self.edgesForExtendedLayout = UIRectEdgeNone; //視圖控制器,四條邊不指定
self.extendedLayoutIncludesOpaqueBars = NO; //不透明的操作欄<br> self.modalPresentationCapturesStatusBarAppearance = NO;
}

 8、圖片展開


// UIImageView 背景(塊地區)展開圖片
UIEdgeInsets imageInsets = UIEdgeInsetsMake(20, 50, 20, 10);
Image = [_tipImage resizableImageWithCapInsets:imageInsets resizingMode:UIImageResizingModeStretch];
UIImageView.image = Image;

// 只展開一個中間像素的方式
UIImage *img=[UIImage imageNamed:@"bubbleSelf.png"];
img=[img stretchableImageWithLeftCapWidth:15 topCapHeight:12];
UIImageView *imgView=[[UIImageView alloc]initWithImage:img];
[imgView setFrame:CGRectMake(10, 10, 200, 200)];
[self. view addSubview:imgView];

IOS——雜集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.