iOSの実用的な知識
3950 ワード
1.buttonにフィレットを設定する
2.cell分割線は画像の下から
3.cellクリックして選択した効果を消して選択したエージェントメソッドに以下のコードを加えるとよい
4.キーボードのイジェクトと消失に応じて入力ボックスの高さを変更します(viewにtabbleViewがあります)
5.画面の明るさを下げる
6.tabbleView自動スクロール下部
7.labelを載せる大きさを知らないことがあります.上の文字がどれだけあるかは確定できません.これにより,文字の数に応じてこのlabelの大きさを計算し,適切なFrameを設定する必要がある.
ここではlabelの幅とフォントの大きさを知る必要があります.皆さんに役に立つことを願っています.
8.story boardによるコントローラのロード
9.cell選択状態チェックの色を変更する
10.オリジナルcell固定画像のサイズ
11.現在のページのVCを取得する
button.clipsToBounds=YES;
button.layer.cornerRadius=30;// 30
[button.layer setBorderWidth:0.5];//
[button.layer setBorderColor:[UIColor grayColor].CGColor];//
2.cell分割線は画像の下から
cell.separatorInset = UIEdgeInsetsZero;
3.cellクリックして選択した効果を消して選択したエージェントメソッドに以下のコードを加えるとよい
[tableView deselectRowAtIndexPath:indexPath animated:YES];
4.キーボードのイジェクトと消失に応じて入力ボックスの高さを変更します(viewにtabbleViewがあります)
// , view
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillChangeFrameNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
// Y
CGFloat endY = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y;
// Y
CGFloat temY = endY - self.view.bounds.size.height;
// frame
self.view.frame = CGRectMake(0, temY, self.view.bounds.size.width, self.view.bounds.size.height);
[UIView animateWithDuration:[note.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{
[self.view setNeedsLayout];
}];
}];
// tabbleview view ,
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self.view endEditing:YES];
}
5.画面の明るさを下げる
[[UIScreen mainScreen] setBrightness: value];//value:value 0 1
注:また、この方法は手動でリフレッシュする必要はありませんが、この方法は携帯電話のインタフェース全体の明るさを調整することです.あるappの明るさだけではありません.つまり、この明るさは完全にこのappを終了した後も保持されます.そのため、この明るさを維持する必要がない場合は、appのエージェント方法で処理する必要があります.// app
- (void)applicationWillResignActive:(UIApplication *)application {
[[UIScreen mainScreen] setBrightness: 0.5];//0.5
}
// :
CGFloat *currentLight = [[UIScreen mainScreen] brightness];
,
6.tabbleView自動スクロール下部
//
- (void)scrollToBottom
{
[_chatView setContentOffset:CGPointMake(0, CGFLOAT_MAX)];
}
7.labelを載せる大きさを知らないことがあります.上の文字がどれだけあるかは確定できません.これにより,文字の数に応じてこのlabelの大きさを計算し,適切なFrameを設定する必要がある.
CGSize textContentSize = [chat.textContent boundingRectWithSize:CGSizeMake(textMaxW, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:TextFont} context:nil].size;
ここではlabelの幅とフォントの大きさを知る必要があります.皆さんに役に立つことを願っています.
8.story boardによるコントローラのロード
// 1. StoryBoard
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
// 2.
UIViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"ID"];
9.cell選択状態チェックの色を変更する
10.オリジナルcell固定画像のサイズ
CGSize itemSize = CGSizeMake(40, 40);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
11.現在のページのVCを取得する
- (UIViewController *)topViewController {
UIViewController *resultVC;
resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
while (resultVC.presentedViewController) {
resultVC = [self _topViewController:resultVC.presentedViewController];
}
return resultVC;
}
- (UIViewController *)_topViewController:(UIViewController *)vc {
if ([vc isKindOfClass:[UINavigationController class]]) {
return [self _topViewController:[(UINavigationController *)vc topViewController]];
} else if ([vc isKindOfClass:[UITabBarController class]]) {
return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
} else {
return vc;
}
return nil;
}
//
UIViewController * topViewController = [self topViewController];