给textview文字添加投影,另外让textview文字居中显示

来源:互联网 发布:清弓的老贾有淘宝店吗? 编辑:程序博客网 时间:2024/06/05 04:09


不能像label那样设置,需要layer层设置

    UITextView *chuanYiTextView     = [UITextViewnew];

    chuanYiTextView.backgroundColor = [UIColorclearColor];

    chuanYiTextView.editable        =NO;

    chuanYiTextView.textColor       = [UIColorwhiteColor];

    chuanYiTextView.font            = [UIFontsystemFontOfSize:11];

    chuanYiTextView.layer.shadowColor = [UIColorgrayColor].CGColor;//阴影颜色

    chuanYiTextView.layer.shadowOffset =CGSizeMake(0.5,1);//偏移距离

    chuanYiTextView.layer.shadowOpacity =1;//不透明度

    chuanYiTextView.layer.shadowRadius =0.8;//半径

    chuanYiTextView.scrollEnabled   =YES;

    [selfaddSubview:chuanYiTextView];

同样可以推出textfield什么的都可以这样设置,记得不要设置self.layer.masksToBounds = YES;

第二个问题

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

    if([textView.textlength]>0) {

        CGSize contentSize = textView.contentSize;

        UIEdgeInsets offset;

        CGSize newSize = contentSize;

        if(contentSize.height <= textView.frame.size.height) {

            CGFloat offsetY = (textView.frame.size.height - contentSize.height)/2;

            offset = UIEdgeInsetsMake(offsetY,0, 0,0);

        }

        else {

            newSize = textView.frame.size;

            offset = UIEdgeInsetsZero;

            CGFloat fontSize =18;

            while (contentSize.height > textView.frame.size.height) {

                [textView setFont:[UIFontfontWithName:@"Helvetica Neue"size:fontSize--]];

                contentSize = textView.contentSize;

            }

            newSize = contentSize;

        }

        [textView setContentSize:newSize];

        [textView setContentInset:offset];

    }

}


哪个textview需要设置传进去就行了


1 0