蘋果開發(fā)工具下載地址
https://developer.apple.com/download/more/
獲取一張隨機(jī)圖片picsum.photos
切換終端對應(yīng)的xcode女淑,Xcode.app根據(jù)自己的名字修改
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
監(jiān)聽UITextField值的變化
[self.textField addTarget:self action:@selector(textChange:) forControlEvents:UIControlEventEditingChanged];
設(shè)置按鈕圖片距右
button.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
靜態(tài)字符串隱藏實現(xiàn)(仿系統(tǒng))
// .h實現(xiàn)
typedef NSString * kCustomKey NS_EXTENSIBLE_STRING_ENUM;
UIKIT_EXTERN kCustomKey const _Nullable CustomKeyType ;
//.m實現(xiàn)
NSString * const CustomKeyType = @"custom_key_type";
Block
//局部block
NSAttributedString *(^createAttrStr)(NSString *, NSString *) = ^NSAttributedString *(NSString *a, NSString *b) {}
createAttrStr(@"數(shù)量",@"123");
@property(nonatomic,copy) void(^block)(NSString *string);//作為屬性
- (void)failure:(nullable void (^)(NSError *error))failure;//作為方法參數(shù)
模擬器鍵盤切換隱藏和顯示
command+k
屏幕旋轉(zhuǎn)
self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
CGRect frame = [UIScreen mainScreen].bounds;
self.view.bounds = CGRectMake(0, 0, frame.size.height, frame.size.width);
更改圖片的顏色
1.代碼更改
UIImage *image = [[UIImage imageNamed:@"***"]imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
//button imageview 設(shè)置顏色后,設(shè)置tintColor
[view setTintColor:[UIColor redColor]];
2.代碼更改
Assets.xcasset——>選擇圖片——>右上角(Render As)選擇 Template Image
xib或者代碼設(shè)置tintColor即可
更改圖片的顏色
使用XIB設(shè)置
UITextField的Clear Button:屬性為Appears while editing
如果用代碼寫,則設(shè)置:
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
刪除SceneDelegate
1.刪除SceneDelegate的.h.m文件。
2.刪除info.plist中的“Application Scene Manifest”項。
3.刪除AppDelegate.m里面關(guān)于SceneDelegate的代碼扼仲。
4.在AppDelegate.h中添加
@property (nonatomic, strong)UIWindow *window;
判斷iPhone的劉海屏幕
#define Is_X \
({BOOL isPhoneX = NO;\
if (@available(iOS 11.0, *)) {\
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;\
}\
(isPhoneX);})
// 導(dǎo)航欄高度
#define TopHeight (Is_X ? 88 : 64)
// TabBar欄高度
#define BottomHeight (Is_X ? (49 + 34) : 49)
//狀態(tài)欄高度
#define NaviTopY (Is_X ? 44 : 20)
//TabBar底部安全區(qū)域
#define TabBottomY (Is_X ? 34 : 0)
取bundle圖片
[UIImage imageNamed:@"***.bundle/imageName"];
UITableView自動高度
//代理返回
UITableViewAutomaticDimension
調(diào)用字符串方法
SEL sel = NSSelectorFromString(methodName);
if (sel) {
IMP imp = [self methodForSelector:sel];
if (imp) {
void *(*func)(id,SEL) = (void *)imp;
func(self,sel);
}
}
view跟隨手指移動
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
[moveView addGestureRecognizer:pan];
- (void)panAction:(UIPanGestureRecognizer *)sender{
CGPoint point = [sender locationInView:xView];//相對于xView的??
if(sender.state == UIGestureRecognizerStateChanged){
CGFloat x = point.x;
//根據(jù)需要更改坐標(biāo)
}
}
取消子view響應(yīng)父view的手勢
//方法1
CGPoint point = [gestureRecognizer locationInView:self.bgView];
BOOL result = [self.bgView.layer containsPoint:point];
//方法2 delegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isDescendantOfView:self.bgView]) {
return NO;
}
return YES;
}