mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +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 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);
|
||||
|
||||
export module ios {
|
||||
export function createBackgroundUIColor(view: viewModule.View): UIColor {
|
||||
export function createBackgroundUIColor(view: viewModule.View, flip?: boolean): UIColor {
|
||||
if(!view._nativeView){
|
||||
return undefined;
|
||||
}
|
||||
@ -64,9 +64,30 @@ export module ios {
|
||||
|
||||
img.drawAsPatternInRect(patternRect);
|
||||
}
|
||||
|
||||
var bkgImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
|
||||
if (flip) {
|
||||
var flippedImage = _flipImage(bkgImage);
|
||||
return UIColor.alloc().initWithPatternImage(flippedImage);
|
||||
}
|
||||
|
||||
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) {
|
||||
var uiLabel: UILabel = <UILabel>view._nativeView;
|
||||
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;
|
||||
uiLabel.layer.backgroundColor = cgColor;
|
||||
}
|
||||
@ -340,12 +341,8 @@ export class LabelStyler implements definition.stylers.Styler {
|
||||
|
||||
private static getNativeBackgroundInternalValue(view: view.View): any {
|
||||
var uiLabel: UILabel = <UILabel>view._nativeView;
|
||||
if (uiLabel && uiLabel.layer) {
|
||||
var cgColor = uiLabel.layer.backgroundColor;
|
||||
if (cgColor) {
|
||||
return UIColor.colorWithCGColor(cgColor);
|
||||
|
||||
}
|
||||
if (uiLabel && uiLabel.layer && uiLabel.layer.backgroundColor) {
|
||||
return UIColor.colorWithCGColor(uiLabel.layer.backgroundColor);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
Reference in New Issue
Block a user