OSStatus TextViewSetBGAlpha( HIViewRef textView, float alpha ) { OSStatus status = paramErr; SInt32 unused; CGColorRef prevColor = NULL; CGColorRef newColor = NULL; status = HITextViewCopyBackgroundColor( textView, &prevColor ); require_noerr( status, FAIL ); // make a new copy with alpha newColor = CGColorCreateCopyWithAlpha( prevColor, alpha ); require_action( newColor != NULL, FAIL, status = paramErr ); // reset the new color with alpha status = HITextViewSetBackgroundColor( textView, newColor ); if( newColor != NULL ) CGColorRelease( newColor ); FAIL: return status; }
//--------------------------------------------------------------------- // Sets the alpha of an HITextView to the specified value // OSStatus TextViewSetAlpha(HIViewRef textView, float alpha) { CGColorRef prevColor, newColor; OSStatus status; status = HITextViewCopyBackgroundColor(textView, &prevColor); require_noerr( status, CantGetBackgroundColor ); newColor = CGColorCreateCopyWithAlpha(prevColor, alpha); require( (newColor != NULL), CantCreateNewColor ); status = HITextViewSetBackgroundColor(textView, newColor); check_noerr( status ); CGColorRelease(newColor); CantCreateNewColor: CGColorRelease(prevColor); CantGetBackgroundColor: return status; }