试了几个例子,这个可行,有需要可以参考:

- (CGFloat)measureHeightOfUITextView:(UITextView *)textView
{
    if ([textView respondsToSelector:@selector(snapshotViewAfterScreenUpdates:)])
    {
        // This is the code for iOS 7. contentSize no longer returns the correct value, so
        // we have to calculate it.
        //
        // This is partly borrowed from HPGrowingTextView, but I've replaced the
        // magic fudge factors with the calculated values (having worked out where
        // they came from)

        CGRect frame = textView.bounds;

        // Take account of the padding added around the text.

        UIEdgeInsets textContainerInsets = textView.textContainerInset;
        UIEdgeInsets contentInsets = textView.contentInset;

        CGFloat leftRightPadding = textContainerInsets.left + textContainerInsets.right + textView.textContainer.lineFragmentPadding * 2 + contentInsets.left + contentInsets.right;
        CGFloat topBottomPadding = textContainerInsets.top + textContainerInsets.bottom + contentInsets.top + contentInsets.bottom;

        frame.size.width -= leftRightPadding;
        frame.size.height -= topBottomPadding;

        NSString *textToMeasure = textView.text;
        if ([textToMeasure hasSuffix:@"\n"])
        {
            textToMeasure = [NSString stringWithFormat:@"%@-", textView.text];
        }

        // NSString class method: boundingRectWithSize:options:attributes:context is
        // available only on ios7.0 sdk.

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];

        NSDictionary *attributes = @{ NSFontAttributeName: textView.font, NSParagraphStyleAttributeName : paragraphStyle };

        CGRect size = [textToMeasure boundingRectWithSize:CGSizeMake(CGRectGetWidth(frame), MAXFLOAT)
                                                  options:NSStringDrawingUsesLineFragmentOrigin
                                               attributes:attributes
                                                  context:nil];

        CGFloat measuredHeight = ceilf(CGRectGetHeight(size) + topBottomPadding);
        return measuredHeight;
    }
    else
    {
        return textView.contentSize.height;
    }
}


摘自:http://stackoverflow.com/q...
以下内容为引用:

In iOS 7, view controllers use full-screen layout. it is mentioned in iOS 7 UI Transition Guide

if you want change the layout use edgesForExtendedLayout property

example:

if([UIViewController instancesRespondToSelector:@selector(edgesForExtendedLayout)])
        self.edgesForExtendedLayout=UIRectEdgeNone;


In "iOS 7 UI Transition Guide" for Layout and Appearance one also mentioned - in iOS7 in, view controllers use the full screen layout.

If we want the view shows the following location from the navigation bar, you can modify the UIViewController's edgesForExtendedLayout this property to achieve.

edgesForExtendedLayout is a type UIExtendedEdge attribute that specifies the direction of the edge to be extended.

Because iOS7 encourage full screen layout, its default value is natural to be UIRectEdgeAll, both extending around the edge, that is, if there is even the view navigationBar, under tabBar, then the view will extend coverage to the surrounding area.

If we make the following settings view, then the view will not be extended to those behind the bar, so label came out. View Source Print

self . edgesForExtendedLayout = UIRectEdgeNone ;

参考自:http://stackoverflow.com/q...
默认的导航栏如下:
点击在新窗口中浏览此图片

带渐变颜色的样子
我们可以改变它的颜色,比如变成红色:

点击在新窗口中浏览此图片

[self.navBar setTintColor:[UIColor redColor]];


但渐变效果还在,我们可以变成纯色的,除了用图片作为背景颜色的方式,也可以用颜色填充:

点击在新窗口中浏览此图片

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.navBar setTintColor:[UIColor redColor]];
    
    UIImage *backgroundImage = [self imageWithColor:[UIColor redColor]];
    [self.navBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];

}

-(UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}


完成~
最近发现几个view的差异很值得注意:

1 - (void)viewDidLoad

视图安装xib文件的布局布置好了,大小读取的都是xib文件的大小哦
如果是ipad用了iphone的视图,那这个将是读取到的iphone的大小

2 -(void)viewWillAppear:(BOOL)animated

正常是视图自适应启动屏幕的大小后的事件
也就是说,上面的情况,读取到的就是ipad的屏幕信息了

3 -(void)viewWillLayoutSubviews

但是,这个是新发现,如果是横屏的xib而启动的时候是竖屏
iphone就很正常的发生这个问题了
第一个事件显示的是横屏的部署的情况哦
第二个事件是,竖屏的自适应后的界面哦
然后才会重新调整布局适应横屏的界面,读取到的才是横屏的屏幕信息
一个文本框是可以自动显示链接,并且可以点击,默认情况下,是由浏览器打开。

    detail.dataDetectorTypes = UIDataDetectorTypeAll;


如上可以设定文本框自动识别链接等内容。

参考How to intercept click on link in UITextView?,可以整理出这样的做法:

重写UIApplication的openURL的方法,步骤如下:

1 建立一个继承类
@interface MyApplication : UIApplication {

}

@end

@implementation MyApplication

-(BOOL)openURL:(NSURL *)url{
    if  ([self.delegate openURL:url])
         return YES;
    else
         return [super openURL:url];
}
@end


2 在appDelegate里面重写这个方法

-(BOOL)openURL:(NSURL *)url
{
    NSLog(@"url=%@",url);
//.... 打开地址
    return YES;
}


3 修改main.m

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
->
return UIApplicationMain(argc, argv, @"MyApplication", NSStringFromClass([AppDelegate class]));


类似如上就OK
分页: 9/26 第一页 上页 4 5 6 7 8 9 10 11 12 13 下页 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐