非开发相关
- mac相关
显示[隐藏文件] defaults write com.apple.finder AppleShowAllFiles -bool true
关闭显示[隐藏文件] defaults write com.apple.finder AppleShowAllFiles -bool false
删除.svn文件 sudo find /Users/justfly/Documents/workspace/justSVN/ -name ".svn" -exec rm -r {} \;
2.Xcode SVN 报错 The server certificate failed to verify.
xcode 的升级或者 切换xcode版本的时候 会出现这种错误
解决办法:1、打开终端(实用工具 -->终端),在终端中输入如下命令:
svn ls https://xxxxxxxx/svn/xxxxxx
SVN的路径然后直接输入 “ p ” 确认,就可以重新连接了。
开发相关
1.访问appdelegate中tabbar,有时访问不到,尝试以下方法:
1. DXTabBarViewController *tabbarVC = SharedApp.tabVCCenter;
[[UIApplication sharedApplication].keyWindow insertSubview:showView aboveSubview:tabbarVC.tabBar];
2. ((UITabBarController *)SharedApp.tabVCCenter).selectedIndex = 1;
3. SharedApp.tabVCCenter.selectedIndex = 2;
2.点击子视图响应父视图问题
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == timeBtn || hitView == addressBtn) {
// 如果当前btn 不需要相应事件 则向下传递
return self;
} else {
return hitView;
}
}
3.系统最小值的宏
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
4.到AppStore评价
1. 7.0以前的系统
NSString *appStore = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=xxxxxx" ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStore]];
2. 7.0以后的系统
NSString *appStore = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/idxxxxxxx"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:appStore]];
3.内置AppStore进行评分
导入StoreKit.framework,添加头文件 #import <StoreKit/StoreKit.h>, 实现代理:< SKStorePRoductViewControllerDelegate >
- (void)loadAppStoreController
{
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
indicator.center = [UIApplication sharedApplication].keyWindow.center;
[indicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
// indicator.color = [UIColor randomColor];
[indicator setBackgroundColor:[UIColor lightGrayColor]];
indicator.hidesWhenStopped = YES;
[self.view addSubview:indicator];
[indicator startAnimating];
// 初始化控制器
SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init];
// 设置代理请求为当前控制器本身
storeProductViewContorller.delegate = self;
[storeProductViewContorller loadProductWithParameters:@{SKStoreProductParameterITunesItemIdentifier:kCPSAppId} completionBlock:^(BOOL result, NSError *error) {
[indicator stopAnimating];
if(error) {
NSLog(@"error %@ with userInfo %@",error,[error userInfo]);
} else {
// 模态弹出appstore
[self presentViewController:storeProductViewContorller animated:YES completion:^{
}];
}
}];
}
//AppStore取消按钮监听
- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController
{
[[UINavigationBar appearance] setTintColor:kMainColor];
[self dismissViewControllerAnimated:YES completion:^{
}];
}
5.UIImageView上添加Button不能响应点击事件
UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
startBtn.frame = CGRectMake(0, 0, 120, 30);
startBtn.top = self.pageControl.bottom + 10;
startBtn.centerX = self.view.centerX;
[startBtn setTitle:@"开启优活动" forState:UIControlStateNormal];
[startBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
startBtn.clipsToBounds = YES;
startBtn.layer.cornerRadius = 3.0;
[startBtn addTarget:self action:@selector(hiddenGuidView) forControlEvents:UIControlEventTouchUpInside];
startBtn.backgroundColor = [self randomColor];
UIColor *normalColor = CSGuidRGBA(224,49,36, 1.0);
UIColor *highlighedColor = CSGuidRGBA(255,86,64, 1.0);
[startBtn setBackgroundImage:[self imageWithColor:normalColor] forState:UIControlStateNormal];
[startBtn setBackgroundImage:[self imageWithColor:highlighedColor] forState:UIControlStateHighlighted];
// 必须设置imageview交互
imgView.userInteractionEnabled = YES;
[imgView addSubview:startBtn];
6.设置tableview.headerView高度
开发过程中若想改变headerView或footerView的高度,需先设置高度,后重新赋值tableHeaderView
self.headerView.height = [DXUtils getGeometricHeight:150];
self.tableView.tableHeaderView = self.headerView;
7.为适应服务器图片,防止图片变形
imgView.clipsToBounds = YES; // 需先设置此选项
imgView.contentMode = UIViewContentModeScaleAspectFill;
8.返回跟视图弹出新页面
DXBaseNavtionViewController *nav = (DXBaseNavtionViewController *)self.navigationController;
[self.navigationController popToRootViewControllerAnimated:NO];
DXMyTicketViewController *ticketVC = [[DXMyTicketViewController alloc]init];
ticketVC.rid = rid;
ticketVC.hidesBottomBarWhenPushed = YES;
[nav pushViewController:ticketVC animated:YES];
9.UITableViewCell中放置UILabel,点击UILabel背景色变透明
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// UIColor *backgroundColor = self.statusLabel.backgroundColor;
// self.statusLabel.backgroundColor = [UIColor redColor];
// Configure the view for the selected state
}
// 防止cell点击label颜色透明
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
self.statusLabel.backgroundColor = MainAppColor;
}
10.UILabel显示html格式数据
比如html为:
<span style="color:#0068b7"><span>D 41F<sub>46</sub>C-10C-DN40</span></span><span style="color:red">(1)</span>
// 设置
NSAttributedString * attrStr = [[NSAttributedString alloc]
initWithData: [titleStr dataUsingEncoding:NSUnicodeStringEncoding]
options: @{
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSFontAttributeName: [UIFont fontWithName:@"Helvetica Neue" size:16.0f]
}
documentAttributes:nil error:nil];
titleLabel.attributedText = attrStr;
11.放大uibutton点击区域
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event {
CGRect bounds = self.bounds;
//若原热区小于44x44,则放大热区,否则保持原大小不变
CGFloat widthDelta = MAX(44.0 - bounds.size.width, 0);
CGFloat heightDelta = MAX(44.0 - bounds.size.height, 0);
bounds = CGRectInset(bounds, -0.5 * widthDelta, -0.5 * heightDelta);
return CGRectContainsPoint(bounds, point);
}
12.uitableview设置默认分割线左右不留白
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
13.xib设置视图高度为0.5(即1px)不起作用
在xib中设置视图高度为0.5时,系统默认更改为1,此时若想使用小数,则需将该约束拖入相应视图中设置一下即可:
{
__weak IBOutlet NSLayoutConstraint *sepViewConstraint;
}
sepViewConstraint.constant = 0.5;
14.引入prefixheader文件
工程 -> targets -> 项目名称 -> Build Settings,搜索prefix header ->
设置“$(SRCROOT)/工程名称/PrefixHeader文件名称”(如:$(SRCROOT)/XibLayerTool/PrefixHeader.h)