魯大師的一些工作筆記

筆記

SVN賬號(hào) luhongwei@2016
luhw

一些方法:
計(jì)算字體高/寬度、獲取拼音方法

視圖效果:抖動(dòng)動(dòng)畫(huà)、圓角、陰影效果

導(dǎo)航欄顏色、摁扭

網(wǎng)頁(yè)搜索

狀態(tài)欄顏色

調(diào)用系統(tǒng)攝像頭、圖庫(kù)、相冊(cè)

一些判斷:
定位權(quán)限、攝像頭、系統(tǒng)版本、判斷設(shè)備

ios10權(quán)限

常用宏:顏色、適配、屏幕尺寸

控件:
scrollview:滑動(dòng)方向、隱藏滑條、某個(gè)方向的彈性

cell:cell內(nèi)數(shù)據(jù)、分割線(xiàn)起止位置、注冊(cè)、選中效果

UItableview:策劃刪除、隱藏空數(shù)據(jù)cell、滑動(dòng)到指定行

UItoolbar:彈性撐開(kāi)效果

UIButton:點(diǎn)擊陰影效果、點(diǎn)擊效果、選中狀態(tài)切換

UIlable:富文本、截?cái)囝?lèi)型、居上居下顯示

UIview:增加手勢(shì)

UItextfield:添加點(diǎn)擊事件、純數(shù)字判斷

UITextView:添加假placeholder、限制文字?jǐn)?shù)量

mac指令

顯示隱藏文件:

defaults write com.apple.finder AppleShowAllFiles -bool true

隱藏隱藏文件:

defaults write com.apple.finder AppleShowAllFiles -bool false
開(kāi)啟本機(jī)服務(wù)器:

sudo apachectl -k start
sudo apachectl -k restart
顯示日歷:

cal 8 2016

不進(jìn)入睡眠狀態(tài):

caffeinate -t 3600

釋放內(nèi)存:

purge

隱藏指定文件:
如果你想讓某個(gè)文件或文件夾影藏,那么chflags命令可以實(shí)現(xiàn)。你只需將文件路徑填對(duì)即可,比如我們向隱藏桌面上的macx文件夾。如果你想再次看到文件夾,只需將hidden改為nohidden即可。

chflags hidden ~/Desktop/macx

創(chuàng)建密碼保護(hù)zip:
-r 包含子文件/文件夾
-e 加密
-m 壓縮完刪除原文件
-o 設(shè)置所有被壓縮文件的最后修改時(shí)間為當(dāng)前壓縮時(shí)間

zip -e protected.zip ~/Desktop/macx.txt
文件夾:
zip -r -e 破解.zip ~/desktop/破解
直接加密:
zip -r -P 690658234 破解.zip 破解

網(wǎng)頁(yè)搜索

Markdown——入門(mén)指南

lua與oc的交互

iOS開(kāi)發(fā)-動(dòng)態(tài)庫(kù)加載(實(shí)時(shí)模塊更新)

iOS hybrid App 的實(shí)現(xiàn)原理及性能監(jiān)測(cè)

阿里wax框架庫(kù)

mac終端命令大全介紹

蘋(píng)果加急審核步驟

extern/static全局變量

切注

手機(jī)app通過(guò)itunes文件共享

Xcode使用快捷方式

字符串操作

歷代版本xcode等蘋(píng)果軟件

iOS圖片拉伸技巧

中間件

iOS獲取當(dāng)前app的名稱(chēng)和版本號(hào)

ios10 相關(guān)

qq臨時(shí)會(huì)話(huà)

交大

社保

>狀態(tài)欄顏色

1在Info.plist中設(shè)置UIViewControllerBasedStatusBarAppearance 為NO
2 在需要改變狀態(tài)欄顏色的ViewController中在ViewDidLoad方法中增加:
[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

如果需要在全部View中都變色,可以寫(xiě)在父類(lèi)的相關(guān)方法中,或者寫(xiě)到AppDelegate中。

>判斷定位權(quán)限

if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {

//定位功能可用

}else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {

//定位不能用

}

判斷是否有攝像頭

  if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){

獲取系統(tǒng)版本

[[[UIDevice currentDevice] systemVersion] floatValue];//獲取系統(tǒng)版本

>判斷版本

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

>判斷設(shè)備

-(NSString *)getCurrentDeviceModel
{
int mib[2];
size_t len;
char *machine;

mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2, NULL, &len, NULL, 0);
machine = malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);

NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);
// iPhone
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone2G";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone3G";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone3GS";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone4";
if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone4";
if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone4";
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone4S";
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone5";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone5";
if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone5c";
if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone5c";
if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone5s";
if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone5s";
if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone6";
if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone6Plus";
if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone6s";
if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone6sPlus";
if ([platform isEqualToString:@"iPhone8,3"]) return @"iPhoneSE";
if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhoneSE";
if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone7";
if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone7Plus";

//iPod Touch
if ([platform isEqualToString:@"iPod1,1"]) return @"iPodTouch";
if ([platform isEqualToString:@"iPod2,1"]) return @"iPodTouch2G";
if ([platform isEqualToString:@"iPod3,1"]) return @"iPodTouch3G";
if ([platform isEqualToString:@"iPod4,1"]) return @"iPodTouch4G";
if ([platform isEqualToString:@"iPod5,1"]) return @"iPodTouch5G";
if ([platform isEqualToString:@"iPod7,1"]) return @"iPodTouch6G";

//iPad
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad2";
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad2";
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad2";
if ([platform isEqualToString:@"iPad2,4"]) return @"iPad2";
if ([platform isEqualToString:@"iPad3,1"]) return @"iPad3";
if ([platform isEqualToString:@"iPad3,2"]) return @"iPad3";
if ([platform isEqualToString:@"iPad3,3"]) return @"iPad3";
if ([platform isEqualToString:@"iPad3,4"]) return @"iPad4";
if ([platform isEqualToString:@"iPad3,5"]) return @"iPad4";
if ([platform isEqualToString:@"iPad3,6"]) return @"iPad4";

//iPad Air
if ([platform isEqualToString:@"iPad4,1"]) return @"iPadAir";
if ([platform isEqualToString:@"iPad4,2"]) return @"iPadAir";
if ([platform isEqualToString:@"iPad4,3"]) return @"iPadAir";
if ([platform isEqualToString:@"iPad5,3"]) return @"iPadAir2";
if ([platform isEqualToString:@"iPad5,4"]) return @"iPadAir2";

//iPad mini
if ([platform isEqualToString:@"iPad2,5"]) return @"iPadmini1G";
if ([platform isEqualToString:@"iPad2,6"]) return @"iPadmini1G";
if ([platform isEqualToString:@"iPad2,7"]) return @"iPadmini1G";
if ([platform isEqualToString:@"iPad4,4"]) return @"iPadmini2";
if ([platform isEqualToString:@"iPad4,5"]) return @"iPadmini2";
if ([platform isEqualToString:@"iPad4,6"]) return @"iPadmini2";
if ([platform isEqualToString:@"iPad4,7"]) return @"iPadmini3";
if ([platform isEqualToString:@"iPad4,8"]) return @"iPadmini3";
if ([platform isEqualToString:@"iPad4,9"]) return @"iPadmini3";
if ([platform isEqualToString:@"iPad5,1"]) return @"iPadmini4";
if ([platform isEqualToString:@"iPad5,2"]) return @"iPadmini4";

if ([platform isEqualToString:@"i386"]) return @"iPhoneSimulator";
if ([platform isEqualToString:@"x86_64"]) return @"iPhoneSimulator";
return platform;
}

IOS10權(quán)限配置

一些常用的權(quán)限配置選項(xiàng)
// 相機(jī)
NSCameraUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)相冊(cè)

// 相冊(cè)
NSPhotoLibraryUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)相機(jī)

// 麥克風(fēng):
NSMicrophoneUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)麥克風(fēng)

// 通信錄
NSContactsUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)通信錄


其它權(quán)限配置選項(xiàng):

// 位置
NSLocationUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)位置

// 在使用期間訪(fǎng)問(wèn)位置
NSLocationWhenInUseUsageDescription
App需要您的同意,才能在使用期間訪(fǎng)問(wèn)位置

// 始終訪(fǎng)問(wèn)位置
NSLocationAlwaysUsageDescription
App需要您的同意,才能始終訪(fǎng)問(wèn)位置

// 日歷
NSCalendarsUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)日歷

// 提醒事項(xiàng)
NSRemindersUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)提醒事項(xiàng)

// 運(yùn)動(dòng)與健身
NSMotionUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)運(yùn)動(dòng)與健身

// 健康更新
NSHealthUpdateUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)健康更新

// 健康分享
NSHealthShareUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)健康分享

// 藍(lán)牙
NSBluetoothPeripheralUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)藍(lán)牙

// 媒體資料庫(kù)
NSAppleMusicUsageDescription
App需要您的同意,才能訪(fǎng)問(wèn)媒體資料庫(kù)

##>常用宏

###顏色
define UIColorFromRGB(value,alp) [UIColor colorWithRed:((float)((value&0xFF0000)>>16))/255.0 green:((float)((value&0xFF00)>>8))/255.0 blue:((float)(value&0xFF))/255.0 alpha:alp]

//余額字體顏色
define balancegraycolor UIColorFromRGB(0x9ed8f9,1.0)
define viewbackgraycolor UIColorFromRGB(0xf1f1f1,1.0)


//屏幕適配
#define LhwRateW           (lhw_ScreenW>375?lhw_ScreenW / 375:1)//橫向放大的比例,小屏不縮放,大屏按比例
#define LhwRateH           ((lhw_ScreenH<667?667:lhw_ScreenH) / 667)//豎直放大的比例,小屏不縮放,大屏按比例
#define LhwAdaptW(w)       ((w) * LhwRateW)//寬度乘以比例
#define LhwAdaptH(h)       (((h)==667&&lhw_ScreenH==480) ? 480 : ((h)*LhwRateH))
#define LhwAdaptFont(f)    ((f) * LhwRateW)
//UIScorllView 專(zhuān)用
#define LhwSLAdaptH(h)    (((h)==667&&lhw_ScreenH==480) ? 568: ((h)*LhwRateH))

#pragma font
#define lhw_font(fontsize) ([UIScreen mainScreen].bounds.size.height == 736) ? [UIFont systemFontOfSize:(fontsize)*LhwRateW]:[UIFont systemFontOfSize:(fontsize)]
###判斷系統(tǒng)版本
    double version = [[UIDevice currentDevice].systemVersion    doubleValue];//判定系統(tǒng)版本。

###判斷尺寸
/**  *  1 判斷是否為3.5inch      320*480  */
define iphone4 ([UIScreen mainScreen].bounds.size.height == 480)
/**  *  2 判斷是否為4inch        640*1136  */
define iphone5 ([UIScreen mainScreen].bounds.size.height == 568)
/**  *  3 判斷是否為4.7inch   375*667   750*1334  */
define iphone6 ([UIScreen mainScreen].bounds.size.height == 667)
/**  *  4 判斷是否為5.5inch   414*736   1242*2208  */
define iphone6p ([UIScreen mainScreen].bounds.size.height == 736)



###中心center
arrowimage2.center=hasreleasetaskimage.center;
CGRect arrowimage2tmp=arrowimage2.frame;
arrowimage2tmp.origin.x+=305;
arrowimage2.frame=arrowimage2tmp;







###全局變量
extern NSString* meString;



#一些方法:
###計(jì)算字體高度、寬度
CGSize resultSize = [data.Commoditydetailstr boundingRectWithSize:CGSizeMake(1000, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:_lhw_font(14)} context:nil].size;

###關(guān)閉自動(dòng)布局
 self.automaticallyAdjustsScrollViewInsets = NO;
 
###系統(tǒng)獲取拼音方法
    
    //系統(tǒng)獲取首字母
- (NSString *) pinyinFirstLetter:(NSString*)sourceString {
NSMutableString *source = [sourceString mutableCopy];
CFStringTransform((__bridge CFMutableStringRef)source, NULL,    kCFStringTransformMandarinLatin, NO);
CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformStripDiacritics, NO);//這一行是去聲調(diào)的
return source;
}

##電話(huà)、短信
//撥打電話(huà) 沒(méi)有彈窗
    NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",_phonenumlab.text]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];
    //電話(huà)有彈窗

UIWebView*callWebview =[[UIWebView alloc] init];  
NSURL *telURL =[NSURL URLWithString:@"tel:10010"];  
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];  
//記得添加到view上  
[self.view addSubview:callWebview];  

//短信

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10010"]];//發(fā)短信  

#視圖效果
### 抖動(dòng)動(dòng)畫(huà)

#pragma mark - 抖動(dòng)動(dòng)畫(huà)
#define Angle2Radian(angle) ((angle) / 180.0 * M_PI)
- (void)shakingAnimation {
anim = [CAKeyframeAnimation animation];
 anim.keyPath = @"transform.rotation";
  anim.values = @[@(Angle2Radian(-4)), @(Angle2Radian(4)), @(Angle2Radian(-4))];
  anim.duration = 0.2;
     // 動(dòng)畫(huà)次數(shù)設(shè)置為最大
     anim.repeatCount = MAXFLOAT;
      // 保持動(dòng)畫(huà)執(zhí)行完畢后的狀態(tài)
      anim.removedOnCompletion = NO;
       anim.fillMode = kCAFillModeForwards;
        [self.layer addAnimation:anim forKey:@"shake"];
}
-(void)stopshak:(UIButton*)sender{
    [self.layer removeAllAnimations];
}

###圓角
 userhead.layer.masksToBounds = YES;  
userhead.layer.cornerRadius = 6.0;  
userhead.layer.borderWidth = 1.0;  
userhead.layer.borderColor = [[UIColor whiteColor] CGColor];

###指定角的圓角
    UIBezierPath *maskPath = [UIBezierPath        bezierPathWithRoundedRect:addremin.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = addremin.bounds;
maskLayer.path = maskPath.CGPath;
addremin.layer.mask = maskLayer;
    
###視圖增加陰影效果
 //加陰影
savebut.layer.shadowColor = lhw_4ecb7b_greencolor.CGColor;//shadowColor陰影顏色
savebut.layer.shadowOffset = CGSizeMake(0,4);//shadowOffset陰影偏移,x向右偏移4,y向下偏移4,默認(rèn)(0, -3),這個(gè)跟shadowRadius配合使用
savebut.layer.shadowOpacity = 0.8;//陰影透明度,默認(rèn)0
savebut.layer.shadowRadius = 7;//陰影半徑,默認(rèn)3

###導(dǎo)航欄背景顏色增加摁扭
UIButton* rightBun = [UIButton buttonWithType:UIButtonTypeCustom];
rightBun.frame = CGRectMake(0, 0, 55, 30);
[rightBun setTitle:@"新增" forState:UIControlStateNormal];
[rightBun addTarget:self action:@selector(additioncontact) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* right = [[UIBarButtonItem alloc] initWithCustomView:rightBun];
self.navigationItem.rightBarButtonItem = right;
NSArray *rightButtons=@[right];
self.navigationItem.rightBarButtonItems= rightButtons;
//導(dǎo)航欄背景顏色
self.navigationController.navigationBar.barTintColor=[UIColor redColor];


    


        
###批量刪除數(shù)組下標(biāo)

    view.mutabletextarr removeObjectsAtIndexes:<#(nonnull NSIndexSet *)#>
#導(dǎo)航欄

//導(dǎo)航欄字體、顏色

self.title=@"收到";
self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor: lhw_3b9dfe_3b9dfecolor, UITextAttributeFont : [UIFont boldSystemFontOfSize:18]};

//導(dǎo)航欄增加摁扭

    UIButton* rightBun = [UIButton buttonWithType:UIButtonTypeCustom];
rightBun.frame = CGRectMake(0, 0, 55, 30);
[rightBun setTitle:@"新增" forState:UIControlStateNormal];
[rightBun addTarget:self action:@selector(additioncontact) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* right = [[UIBarButtonItem alloc] initWithCustomView:rightBun];
self.navigationItem.rightBarButtonItem = right;
NSArray *rightButtons=@[right];
self.navigationItem.rightBarButtonItems= rightButtons;


# 系統(tǒng)攝像頭、相冊(cè)、照片
-(void)selectedImageForIcon
{

UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *actionCamera=[UIAlertAction actionWithTitle:@"打開(kāi)相機(jī)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    myaccount.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
//        [UIImagePickerController availableCaptureModesForCameraDevice:UIImagePickerControllerCameraDeviceFront];
   myaccount.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;//前攝像頭
    [self presentViewController:myaccount.imagePicker animated:YES completion:nil];

}];

UIAlertAction *actionPhotoLIbrary=[UIAlertAction actionWithTitle:@"打開(kāi)相冊(cè)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    myaccount.imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:myaccount.imagePicker animated:YES completion:nil];

}];

UIAlertAction *actionPhotoAlbum=[UIAlertAction actionWithTitle:@"打開(kāi)圖庫(kù)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    myaccount.imagePicker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentViewController:myaccount.imagePicker animated:YES completion:nil];

}];

UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

[alertController addAction:actionCamera];

[alertController addAction:actionPhotoAlbum];

[alertController addAction:actionPhotoLIbrary];

[alertController addAction:cancelAction];
alertController.isShowNavBars = YES;
[self presentViewController:alertController animated:YES completion:nil];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary *)editingInfo
{

//    _selectedRightImage.image=image;
[myaccount.headimage setImage:image forState:UIControlStateNormal];

[self dismissViewControllerAnimated:YES completion:nil];

}

#++++++++++++++++++++++++++++++++++++++++++


#控件

#scrollview

###判斷scrollview的滑動(dòng)方向

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
historyY = scrollView.contentOffset.y;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
  if (scrollView.contentOffset.yhistoryY) {
    NSLog(@"向上");

    }
###scrollview隱藏滑動(dòng)條
webview.scrollView.showsVerticalScrollIndicator = FALSE;
webview.scrollView.showsHorizontalScrollIndicator = FALSE;

###scrollview某個(gè)方向去除彈性效果

  scrollView.bounces = (scrollView.contentOffset.y <= 0) ? NO : YES;


##Cell
##獲取cell內(nèi)數(shù)據(jù)
    NSIndexPath* indexpath=[NSIndexPath indexPathForRow:0 inSection:0 ];
LhwBindingAlipayCell* cell=[alipaytableview cellForRowAtIndexPath:indexpath];
####Cell分割線(xiàn)的設(shè)置
//分割線(xiàn)的長(zhǎng)度    [lhwcell setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 10)];
 去除分割線(xiàn):  self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

 //cell自定義起止位置
 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIEdgeInsets tmp =UIEdgeInsetsMake(0,11.5, 0, 10);

if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
    [tableView setLayoutMargins:tmp];
    [cell setLayoutMargins:tmp];
}
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [tableView setSeparatorInset:tmp];
    [cell setSeparatorInset:tmp];
}
}
###cell注冊(cè)
//自定義cell
    [myTrackingtableview registerClass:[LhwMyTrackingCell class] forCellReuseIdentifier:@"LhwMyTrackingCell"];
       LhwMyTrackingCell* lhwcell = [tableView dequeueReusableCellWithIdentifier:@"LhwMyTrackingCell" forIndexPath:indexPath];
lhwcell.selectionStyle = UITableViewCellSelectionStyleNone;
//系統(tǒng)cell
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lhwcell"];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"lhwcell"] ;
}
****
###取消cell選中效果
lhwcell.selectionStyle = UITableViewCellSelectionStyleNone;


##UItableview
###tableview 策劃刪除

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"刪除";
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

// 從數(shù)據(jù)源中刪除
[dataarr removeObjectAtIndex:indexPath.row];
// 從列表中刪除
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
###隱藏tableview空數(shù)據(jù)cell
 [self setExtraCellLineHidden:myAttentiontableview];
//隱藏空數(shù)據(jù)時(shí)候的tableviewcell線(xiàn)
    -(void)setExtraCellLineHidden: (UITableView *)tableView
{
   UIView *view = [UIView new];
   view.backgroundColor = [UIColor clearColor];
 [tableView setTableFooterView:view];
}

###tableview滑動(dòng)到指定行
[table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:arr.count+1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

     
###toolbar 中的彈簧撐開(kāi)效果
                UIBarButtonItem* but=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelchoice)];
        [but setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14], NSFontAttributeName, nil] forState:UIControlStateNormal];

        UIBarButtonItem* butright=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(cancelchoice)];
        [butright setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14], NSFontAttributeName, nil] forState:UIControlStateNormal];

        UIBarButtonItem *btn4=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

        UIToolbar*  toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0 ,lhw_ScreenW, 25)];
        [toolBar setBarStyle:UIBarStyleDefault];
        toolBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
        [toolBar setItems:[NSArray arrayWithObjects:but,btn4,butright,nil]];
        [choiceview addSubview:toolBar];

  
##UIButton

//摁扭的點(diǎn)擊時(shí)候的陰影效果

      button.adjustsImageWhenHighlighted = NO;
//摁扭上的圖片與周邊間距

       [button.setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
//摁扭選中狀態(tài)切換

[but setImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];
[but setImage:[UIImage imageNamed:@"1.jpg"] forState: UIControlStateHighlighted];
[but setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateSelected];
[but setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
[but addTarget:self action:@selector(buttonClick:)    forControlEvents:UIControlEventTouchUpInside];

- (void)buttonClick:(UIButton *)sender {
sender.selected = !sender.selected;
NSLog(@"%d",sender.selected);
}



    
##UILable
##富文本
 NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"獲得%d積分",countbum]];
        //獲取數(shù)字所在的位置
        [prizeinformationlab.text rangeOfString:[NSString stringWithFormat:@"%d",countbum]];
        NSRange ranegtmp=[strtmp rangeOfString:[NSString stringWithFormat:@"%d",countbum]];
        [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Impact" size:36] range:ranegtmp];
        prizeinformationlab.attributedText=attrString;


##Lable截?cái)囝?lèi)型
_waringdeslab.lineBreakMode=NSLineBreakByCharWrapping;//字符截?cái)?###Lable居上顯示
#pragma mark 居上顯示
-(void)alignTop:(UILabel*)lable
{
NSLog(@"%@",lable.font);
// 對(duì)應(yīng)字號(hào)的字體一行顯示所占寬高
CGSize fontSize = [lable.text sizeWithAttributes:@{NSFontAttributeName:lable.font}];
// 多行所占 height*line
double height = fontSize.height*numberOfLines;
// 顯示范圍實(shí)際寬度
double width = self.frame.size.width;
// 對(duì)應(yīng)字號(hào)的內(nèi)容實(shí)際所占范圍
CGSize stringSize = [lable.text boundingRectWithSize:CGSizeMake(width, height) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:lable.font} context:nil].size;
// 剩余空行
NSInteger line = (height - stringSize.height) / fontSize.height;
// 用回車(chē)補(bǔ)齊
for (int i = 0; i < line; i++) {
    lable.text = [lable.text stringByAppendingString:@"\n "];
}
}

###Lable居下顯示
#pragma mark居下顯示
-(void)alignBottom  
{  
CGSize fontSize = [self.text sizeWithAttributes:@{NSFontAttributeName:self.font}];  
double height = fontSize.height*self.numberOfLines;  
double width = self.frame.size.width;  
CGSize stringSize = [self.text boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.font} context:nil].size;  

NSInteger line = (height - stringSize.height) / fontSize.height;  
// 前面補(bǔ)齊換行符  
for (int i = 0; i < line; i++) {  
    self.text = [NSString stringWithFormat:@" \n%@", self.text];  
}  
}    

    
###UIView
//設(shè)置父視圖透明,子視圖不透明
        contactbackview.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.7];
        
###view增加點(diǎn)擊手勢(shì)
//添加手勢(shì)
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickbackview)];
//將手勢(shì)添加到需要相應(yīng)的view中去
[backview addGestureRecognizer:tapGesture];
//選擇觸發(fā)事件的方式(默認(rèn)單機(jī)觸發(fā))
[tapGesture setNumberOfTapsRequired:1];    


   
##UITextField
###uitextfield添加事件
[phonenumtext addTarget:self action:@selector(textFiledEditChanged:) forControlEvents:UIControlEventEditingChanged];
###UITextField 純數(shù)字判斷
#pragma mark 純數(shù)字控制
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:    (NSRange)range replacementString:(NSString *)string {
return [self validateNumber:string];
    }
- (BOOL)validateNumber:(NSString*)number {
BOOL res = YES;
NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
int i = 0;
while (i < number.length) {
    NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
    NSRange range = [string rangeOfCharacterFromSet:tmpSet];
    if (range.length == 0) {
        res = NO;
        break;
    }
    i++;
}
return res;
}  

##UITextView
###UITextView假placehold
    placehoderlab=[[UILabel alloc]initWithFrame:CGRectMake(5,5+2, 170, 20)];
[sencedestext addSubview:placehoderlab];
placehoderlab.text=@"請(qǐng)輸入您的需求";
placehoderlab.font=lhw_font(15);
placehoderlab.textColor=lhw_cccccc_graycolor;

#pragma mark textview代理
- (void)textViewDidBeginEditing:(UITextView *)textView {
if (sencedestext.text.length<1) {
    placehoderlab.hidden=NO;
}else{
    placehoderlab.hidden=YES;
}
}

- (void)textViewDidEndEditing:(UITextView *)textView {
if (sencedestext.text.length<1) {
    placehoderlab.hidden=NO;
}else{
    placehoderlab.hidden=YES;
}
}

-(void)textViewDidChange:(UITextView *)textView{

if (sencedestext.text.length<1) {
    placehoderlab.hidden=NO;
}else{
    placehoderlab.hidden=YES;
}

}

###UITextView限制輸入文字?jǐn)?shù)量
    if (sencedestext.text.length>500) {
    sencedestext.text=[sencedestext.text substringWithRange:NSMakeRange(0, 500)];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容