Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions EGOTextView/EGOTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ extern NSString * const EGOTextAttachmentPlaceholderString;
@property(nonatomic,copy) NSAttributedString *attributedString;
@property(nonatomic,copy) NSString *text;
@property(nonatomic,retain) UIFont *font; // ignored when attributedString is not nil
@property(nonatomic,retain) UIColor *textColor;
@property(nonatomic,getter=isEditable) BOOL editable; //default YES
@property(nonatomic) NSRange selectedRange;
@property(nonatomic) NSRange markedRange;
Expand Down
36 changes: 29 additions & 7 deletions EGOTextView/EGOTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ @implementation EGOTextView
@synthesize attributedString=_attributedString;
@synthesize text=_text;
@synthesize font=_font;
@synthesize textColor=_textColor;
@synthesize editable=_editable;
@synthesize markedRange=_markedRange;
@synthesize selectedRange=_selectedRange;
Expand Down Expand Up @@ -268,6 +269,7 @@ - (void)dealloc {

_textWindow=nil;
[_font release], _font=nil;
[_textColor release], _textColor = nil;
[_attributedString release], _attributedString=nil;
[_caretView release], _caretView=nil;
self.menuItemActions=nil;
Expand Down Expand Up @@ -353,20 +355,40 @@ - (NSString *)text {
return _attributedString.string;
}

-(void)buildDefaultAttributes
{
CTFontRef ctFont = CTFontCreateWithName((CFStringRef) self.font.fontName, self.font.pointSize, NULL);
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:(id)ctFont, (NSString *)kCTFontAttributeName, (id)self.textColor.CGColor, kCTForegroundColorAttributeName, nil];
self.defaultAttributes = dictionary;
[dictionary release];
CFRelease(ctFont);

[self textChanged];
}

-(void)setTextColor:(UIColor *)textColor
{
UIColor *oldTextColor = _textColor;
_textColor = [textColor retain];
[oldTextColor release];

[self buildDefaultAttributes];
}

- (void)setFont:(UIFont *)font {

UIFont *oldFont = _font;
_font = [font retain];
[oldFont release];

CTFontRef ctFont = CTFontCreateWithName((CFStringRef) self.font.fontName, self.font.pointSize, NULL);
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:(id)ctFont, (NSString *)kCTFontAttributeName, (id)[UIColor blackColor].CGColor, kCTForegroundColorAttributeName, nil];
self.defaultAttributes = dictionary;
[dictionary release];
CFRelease(ctFont);

[self textChanged];
[self buildDefaultAttributes];
}

-(void)setBackgroundColor:(UIColor *)backgroundColor
{
[super setBackgroundColor:backgroundColor];

self.textInputView.backgroundColor = backgroundColor;
}

- (void)setText:(NSString *)text {
Expand Down