向 UITextView 的框架添加陰影 也向文本添加陰影 (Add shadow to frame of UITextView add also shadow to text)


問題描述

向 UITextView 的框架添加陰影 也向文本添加陰影 (Add shadow to frame of UITextView add also shadow to text)

I have a UITextView where I add some drop shadow to the frame, but when I write, the text got also the same shadow. How to avoid this problem? 

My code : 

commentary = [[UITextView alloc]initWithFrame:CGRectMake(10, 435, 230, 120)];
commentary.font = STANDARDFONT;
commentary.backgroundColor = BACKGROUND;
commentary.layer.shadowColor = [UIColor blackColor].CGColor;
commentary.layer.shadowOffset = CGSizeMake(2, 2);
commentary.layer.shadowOpacity = 0.8;
commentary.layer.shadowRadius = 2.0;
commentary.layer.borderColor = [UIColor grayColor].CGColor;
commentary.layer.borderWidth = 1.5;
commentary.layer.cornerRadius = 5;
commentary.layer.masksToBounds = NO;
commentary.clipsToBounds = NO;
[self addSubview:commentary];

BACKGROUND and STANDARDFONT is [UICOLOR clearColor].CGColorand [UIFont fontWithName:@"TimesNewRomanPSMT" size:16];

‑‑‑‑‑

參考解法

方法 1:

Try setting the layer background color also: commentary.layer.backgroundColor = BACKGROUND.CGColor

(by lagosBek)

參考文件

  1. Add shadow to frame of UITextView add also shadow to text (CC BY‑SA 3.0/4.0)

#uitextview #iOS #dropshadow #quartz-core






相關問題

textViewDidBeginEditing 由於縮放而未觸發 (textViewDidBeginEditing not firing due to zoom)

如何在 UITextView 下添加 UIImageViews(UITextView 跨越整個屏幕) (How do you add a UIImageViews under a UITextView (the UITextView spans entire screen))

UITextView tidak mengaktifkan textViewDidChange pada perubahan atribut? (UITextView not firing textViewDidChange on attribute change?)

向 UITextView 的框架添加陰影 也向文本添加陰影 (Add shadow to frame of UITextView add also shadow to text)

uitextview 字體不隨 fontWIthName 改變 (uitextview font not changing with fontWIthName)

帶有自己的 UIToolbar 的 UITextView 和 UIPickerView (UITextView and UIPickerView with its own UIToolbar)

為什麼 UITextView 的 text 屬性使用字符串而不是可變字符串? (Why does UITextView use string rather than mutable string for its text property?)

UILabel 中的多行文本 (Multiple lines of text in UILabel)

如何在 iPhone 的 UITextView 中嵌入鏈接 (How to embed a link in a UITextView for the iphone)

UITextView - 修改選定的文本 (UITextView - modifying selected text)

如何以編程方式將鍵盤視圖從“符號”重置為“字母” (How to reset keyboard view from 'symbols' to 'alphabet' programmatically)

UITextView 不會更改 textColor 屬性 (UITextView does not change textColor property)







留言討論