Lydia's blog

Every day to be a little better


  • Home

  • Archives

  • Search

ios- nav title

Posted on 2018-04-22 12:00

1.直接修改默认
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSFontAttributeName:[UIFont systemFontOfSize:19],
NSForegroundColorAttributeName:[UIColor redColor]}];

2.就是在导航向上添加一个titleView,可以使用一个label,再设置label的背景颜色透明,字体什么的设置就很简单了。
//自定义标题视图
UILabel *titleLabel = [[UILabel
alloc] initWithFrame:CGRectMake(0,
0, 200, 44)];
titleLabel.backgroundColor = [UIColor grayColor];
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.textColor = [UIColor greenColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text =
@”新闻”;
self.navigationItem.titleView = titleLabel;

ps:定义普通字符串大小颜色:
UIFont *font = [UIFont fontWithName:@”Palatino-Roman” size:14.0];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@”strigil” attributes:attrsDictionary];

ios-navigationbar 按钮偏移

Posted on 2018-04-19 14:42

在ios11之前 我们用

1
2
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
space.width = -13;

但是他在ios11里失效了我们可以选择
leftBtn.contentEdgeInsets =UIEdgeInsetsMake(0, -20,0, 0);
来调整位置
barbtn 我还没有找到一个合适的方法

toolbar 拼接要写两种

ps:UIEdgeInsetsMake 上 左 下 右

ios-wkwebview 加载完成方法

Posted on 2018-04-18 17:39
  • (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {}

css-box-shadow

Posted on 2018-04-17 15:41

box-shadow语法:x轴偏移值 y轴偏移值 模糊半径 阴影半径 || 颜色 insect,其中阴影半径可以为负值,意思是增加或减少指定数值的阴影半径

正常阴影 box-shadow: 5px 5px 5px black;

阴影半径为负值 box-shadow: 5px 5px 5px -5px black;

阴影半径为正值 box-shadow: 5px 5px 5px 5px black;

双边阴影 box-shadow: 5px 0px 5px -5px black, -5px 0px 5px -5px black;

单边阴影 box-shadow: 5px 0px 5px -5px black;

ios-UIActionSheet

Posted on 2018-04-17 10:07

ios8.3之前用UIActionSheet

1
2
3
4
5
6
7
8
UIActionSheet *actionSheet = [[UIActionSheet alloc]  
initWithTitle:@"这是UIActionSheet"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"确定"
otherButtonTitles:@"按钮1", @"按钮2",nil];
actionSheet.actionSheetStyle = UIBarStyleDefault;
[actionSheet showInView:self.view];

之后ios更新了UIAlertController 添加了一种样式:UIAlertControllerStyleActionSheet 来替代UIActionSheet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
UIAlertController *actionSheet=[UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertController *actionSheet=[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];//取消上面的title
//红色按钮
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"否按钮被点击了");
}];
//蓝色按钮
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"是按钮被点击了");
}];
//取消按钮
UIAlertAction *destructiveAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"关闭按钮被点击了");
}];

[actionSheet addAction:cancelAction];
[actionSheet addAction:sureAction];
[actionSheet addAction:destructiveAction];

[self presentViewController:actionSheet animated:YES completion:nil];

ios-左滑返回

Posted on 2018-04-16 14:34

self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

ios-wkwebview页面双击会上移

Posted on 2018-04-13 17:36

(function()
{
var agent = navigator.userAgent.toLowerCase(); //检测是否是ios
var iLastTouch = null; //缓存上一次tap的时间
if (agent.indexOf(‘iphone’) >= 0 || agent.indexOf(‘ipad’) >= 0)
{
document.body.addEventListener(‘touchend’, function(event)
{
var iNow = new Date()
.getTime();
iLastTouch = iLastTouch || iNow + 1 /** 第一次时将iLastTouch设为当前时间+1 */ ;
var delta = iNow - iLastTouch;
if (delta < 500 && delta > 0)
{
event.preventDefault();
return false;
}
iLastTouch = iNow;
}, false);
}

})();

ios-给navbar tabbar 加分割线

Posted on 2018-04-12 15:45

1.创建UIimage的类方法 imageWithUicolor

1
2
3
4
5
6
7
8
9
10
11
12
@implementation UIImage (color)
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,color.CGColor);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return img;
}

2-navbar.页面上调用setShadowImage方法

1
[self.navigationController.navigationBar setShadowImage:[UIImage imageWithColor:BORDERGRAY size:CGSizeMake(SCREEN_WIDTH, 0.5)]];

ps:不要分割线
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
2-tabbar.页面上调用setShadowImage方法

1
[self.tabBarsetShadowImage:[UIImage imageWithColor:BORDERGRAY size:CGSizeMake(SCREEN_WIDTH, 0.5)]];

ps: 创建类方法要选用object-c file —> category —-> uiimage
写完方法后要记得引用!

ps:如果不是用navigation controller这样来做的 就给uiview 添加了一个subview就可以了
横线:

1
2
3
UIView *horizontalLine = [[UIView alloc]initWithFrame:CGRectMake(x, y, SCREEN_WIDTH, 1)];
horizontalLine.backgroundColor = BORDERGRAY;
[self.tabBar addSubview:horizontalLine];

竖线:

1
2
3
UIView *verticalLine = [[UIView alloc]initWithFrame:CGRectMake(x cordinate, y cordinate, 1, viewWidth())];
verticalLine.backgroundColor = [UIColor grayColor];
[self.view addSubview:verticalLine];

css-select text align

Posted on 2018-04-10 18:09

text-align-last: right;

h5-ipnonex适配

Posted on 2018-04-04 16:47

一般适配问题不大 但是如果遇到底部按钮的那种就会很奇怪 尤其是集成到ios 的wkwebview 之后

设置meta标签
ios11为了适配iphoneX对现有的viewport meta标签新增一个特性:viewport-fit,如果客户端没有做全屏适配,那么页面想要全屏覆盖,则可使用该特性:

可以通过加内边距 padding 扩展高度:不好使

{
padding-bottom: constant(safe-area-inset-bottom);
padding-bottom: env(safe-area-inset-bottom);
}
或者通过计算函数 calc 覆盖原来高度:会跳

{
height: calc(60px(假设值) + constant(safe-area-inset-bottom));
height: calc(60px(假设值) + env(safe-area-inset-bottom));
}
注意,这个方案需要吸底条必须是有背景色的,因为扩展的部分背景是跟随外容器的,否则出现镂空情况。

还有一种方案就是,可以通过新增一个新的元素(空的颜色块,主要用于小黑条高度的占位),然后吸底元素可以不改变高度只需要调整位置,像这样:会跳

{
margin-bottom: constant(safe-area-inset-bottom);
margin-bottom: env(safe-area-inset-bottom);
}
空的颜色块:

{
position: fixed;
bottom: 0;
width: 100%;
height: constant(safe-area-inset-bottom);
height: env(safe-area-inset-bottom);
background-color: #fff;
}

类型二:fixed 非完全吸底元素(bottom ≠ 0),比如 “返回顶部”、“侧边广告” 等
像这种只是位置需要对应向上调整,可以仅通过外边距 margin 来处理:
{
margin-bottom: constant(safe-area-inset-bottom);
margin-bottom: env(safe-area-inset-bottom);
}
或者,你也可以通过计算函数 calc 覆盖原来 bottom 值:
{
bottom: calc(50px(假设值) + constant(safe-area-inset-bottom));
bottom: calc(50px(假设值) + env(safe-area-inset-bottom));
}

ps:在实现的过程中发现,html是否充满页面会影响底部按钮的适配,如果页面高度不变
则不充满屏幕的页面可以用 加内边距 padding 扩展高度
充满屏幕的用 计算函数 calc 覆盖原来高度(会闪 这个时候可以用下面的将iPhone X的写成单独的css)
但是有的页面高度是通过js可能会变化的 这个时候还没找到很好的解决办法
padding方法适配的iphonex css height在iPhonex的浏览器里不行 padding 的微信上不行 height env 在 app里会跳

判断是否是iphoneX可以将iPhonex的单独写css

1、利用constant函数

只有设置了viewport-fit=cover才能使用constant函数

@supports(bottom:constant(safe-area-inset-bottom)) {
selector{
padding-bottom:constant(safe-area-inset-bottom);
padding-bottom:calc(30px(假设值) + constant(safe-area-inset-bottom)); //根据实际情况选择适配方法
}
}
2、利用iphoneX独特的型号参数

@media only screen and (device-width: 375px) and (device-height:812px) and (-webkit-device-pixel-ratio:3) {
#buy {
padding-bottom:34px;
}

}

//iphoneX、iphoneXs
@media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
}
即: 设备屏幕可见宽度为375px, 可见高度为812px及设备像素比为3

//iphone Xs Max
@media only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio:3) {
}

//iphone XR
@media only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio:2) {
}

(3)js判断(以下采用Jquery)

if($(window).width() === 375 && $(window).height() === 724 && window.devicePixelRatio === 3){
#buy {
padding-bottom:34px;
}

}

ps: 6/7/8 width: 375 height: 553 devicePixelRatio: 2
6p/7p/8p width: 442 height: 622 devicePixelRatio: 3
x width: 375 height: 674 devicePixelRatio: 3

1…141516…28

Lydia

This is lydia's blog

277 posts
1 categories
46 tags
© 2020 Lydia
Powered by Hexo
|
Theme — NexT.Muse v5.1.4