mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Fixed Issue #1160: The image supplied to Label.backgroundImage is rendered upside down
This commit is contained in:
2
ui/styling/background.d.ts
vendored
2
ui/styling/background.d.ts
vendored
@ -44,6 +44,6 @@ declare module "ui/styling/background" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export module ios {
|
export module ios {
|
||||||
export function createBackgroundUIColor(view: viewModule.View): any /* UIColor */;
|
export function createBackgroundUIColor(view: viewModule.View, flip?: boolean): any /* UIColor */;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import common = require("./background-common");
|
|||||||
global.moduleMerge(common, exports);
|
global.moduleMerge(common, exports);
|
||||||
|
|
||||||
export module ios {
|
export module ios {
|
||||||
export function createBackgroundUIColor(view: viewModule.View): UIColor {
|
export function createBackgroundUIColor(view: viewModule.View, flip?: boolean): UIColor {
|
||||||
if(!view._nativeView){
|
if(!view._nativeView){
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -64,9 +64,30 @@ export module ios {
|
|||||||
|
|
||||||
img.drawAsPatternInRect(patternRect);
|
img.drawAsPatternInRect(patternRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
var bkgImage = UIGraphicsGetImageFromCurrentImageContext();
|
var bkgImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||||
UIGraphicsEndImageContext();
|
UIGraphicsEndImageContext();
|
||||||
|
|
||||||
|
if (flip) {
|
||||||
|
var flippedImage = _flipImage(bkgImage);
|
||||||
|
return UIColor.alloc().initWithPatternImage(flippedImage);
|
||||||
|
}
|
||||||
|
|
||||||
return UIColor.alloc().initWithPatternImage(bkgImage);
|
return UIColor.alloc().initWithPatternImage(bkgImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flipping the default coordinate system
|
||||||
|
// https://developer.apple.com/library/ios/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GraphicsDrawingOverview/GraphicsDrawingOverview.html
|
||||||
|
function _flipImage(originalImage: UIImage): UIImage {
|
||||||
|
UIGraphicsBeginImageContextWithOptions(originalImage.size, false, 0.0);
|
||||||
|
var context = UIGraphicsGetCurrentContext();
|
||||||
|
CGContextSaveGState(context);
|
||||||
|
CGContextTranslateCTM(context, 0.0, originalImage.size.width);
|
||||||
|
CGContextScaleCTM(context, 1.0, -1.0);
|
||||||
|
originalImage.drawInRect(CGRectMake(0, 0, originalImage.size.width, originalImage.size.height))
|
||||||
|
CGContextRestoreGState(context);
|
||||||
|
var flippedImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||||
|
UIGraphicsEndImageContext();
|
||||||
|
return flippedImage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,7 +323,8 @@ export class LabelStyler implements definition.stylers.Styler {
|
|||||||
private static setBackgroundInternalProperty(view: view.View, newValue: any) {
|
private static setBackgroundInternalProperty(view: view.View, newValue: any) {
|
||||||
var uiLabel: UILabel = <UILabel>view._nativeView;
|
var uiLabel: UILabel = <UILabel>view._nativeView;
|
||||||
if (uiLabel && uiLabel.layer) {
|
if (uiLabel && uiLabel.layer) {
|
||||||
var uiColor = <UIColor>background.ios.createBackgroundUIColor(view);
|
var flipImage = true;
|
||||||
|
var uiColor = <UIColor>background.ios.createBackgroundUIColor(view, flipImage);
|
||||||
var cgColor = uiColor ? uiColor.CGColor : null;
|
var cgColor = uiColor ? uiColor.CGColor : null;
|
||||||
uiLabel.layer.backgroundColor = cgColor;
|
uiLabel.layer.backgroundColor = cgColor;
|
||||||
}
|
}
|
||||||
@ -340,12 +341,8 @@ export class LabelStyler implements definition.stylers.Styler {
|
|||||||
|
|
||||||
private static getNativeBackgroundInternalValue(view: view.View): any {
|
private static getNativeBackgroundInternalValue(view: view.View): any {
|
||||||
var uiLabel: UILabel = <UILabel>view._nativeView;
|
var uiLabel: UILabel = <UILabel>view._nativeView;
|
||||||
if (uiLabel && uiLabel.layer) {
|
if (uiLabel && uiLabel.layer && uiLabel.layer.backgroundColor) {
|
||||||
var cgColor = uiLabel.layer.backgroundColor;
|
return UIColor.colorWithCGColor(uiLabel.layer.backgroundColor);
|
||||||
if (cgColor) {
|
|
||||||
return UIColor.colorWithCGColor(cgColor);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
Reference in New Issue
Block a user