mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
FontAwesome will now work in iOS buttons, being bold will fallback to Helvetica
This commit is contained in:
@ -8,38 +8,38 @@
|
||||
<Label text="" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" />
|
||||
<Button text="TAP" tap="onTap">
|
||||
<FormattedString>
|
||||
<Span text="" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
||||
<Span text="font-awesome" fontAttributes="Bold"></Span>
|
||||
<Span text="" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||
<Span text="font-awesome" fontWeight="bold"></Span>
|
||||
</FormattedString>
|
||||
</Button>
|
||||
<Button text="TAP" tap="onTap" class="">
|
||||
<FormattedString>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
||||
<Span text="some text" fontAttributes="Bold"></Span>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||
<Span text="some text" fontWeight="bold"></Span>
|
||||
</FormattedString>
|
||||
</Button>
|
||||
<Button text="TAP" tap="onTap" class="">
|
||||
<FormattedString>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
||||
<Span text="some text" fontAttributes="Bold"></Span>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||
<Span text="some text" fontWeight="bold"></Span>
|
||||
</FormattedString>
|
||||
</Button>
|
||||
<Button text="TAP" tap="onTap" class="">
|
||||
<FormattedString>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
||||
<Span text="some text" fontAttributes="Bold"></Span>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||
<Span text="some text" fontWeight="bold"></Span>
|
||||
</FormattedString>
|
||||
</Button>
|
||||
<Button text="TAP" tap="onTap" class="">
|
||||
<FormattedString>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
||||
<Span text="some text" fontAttributes="Bold"></Span>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||
<Span text="some text" fontWeight="bold"></Span>
|
||||
</FormattedString>
|
||||
</Button>
|
||||
<Button text="TAP" tap="onTap" class="">
|
||||
<FormattedString>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
||||
<Span text="some text" fontAttributes="Bold"></Span>
|
||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||
<Span text="some text" fontWeight="bold"></Span>
|
||||
</FormattedString>
|
||||
</Button>
|
||||
<Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Definitions.
|
||||
import { TextBase as TextBaseDefinition } from ".";
|
||||
import { FontWeight } from "../styling/font";
|
||||
import { FontStyle, FontWeight } from "../styling/font";
|
||||
import { PropertyChangeData } from "../../data/observable";
|
||||
|
||||
// Types.
|
||||
@ -19,6 +19,13 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition
|
||||
public text: string;
|
||||
public formattedText: FormattedString;
|
||||
|
||||
get fontFamily(): string {
|
||||
return this.style.fontFamily;
|
||||
}
|
||||
set fontFamily(value: string) {
|
||||
this.style.fontFamily = value;
|
||||
}
|
||||
|
||||
get fontSize(): number {
|
||||
return this.style.fontSize;
|
||||
}
|
||||
@ -26,6 +33,20 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition
|
||||
this.style.fontSize = value;
|
||||
}
|
||||
|
||||
get fontStyle(): FontStyle {
|
||||
return this.style.fontStyle;
|
||||
}
|
||||
set fontStyle(value: FontStyle) {
|
||||
this.style.fontStyle = value;
|
||||
}
|
||||
|
||||
get fontWeight(): FontWeight {
|
||||
return this.style.fontWeight;
|
||||
}
|
||||
set fontWeight(value: FontWeight) {
|
||||
this.style.fontWeight = value;
|
||||
}
|
||||
|
||||
get letterSpacing(): number {
|
||||
return this.style.letterSpacing;
|
||||
}
|
||||
|
@ -234,37 +234,9 @@ export class TextBase extends TextBaseCommon {
|
||||
let fontSize = span.fontSize;
|
||||
|
||||
if (bold || italic || fontFamily || fontSize) {
|
||||
if (!fontSize) {
|
||||
fontSize = viewFont.pointSize;
|
||||
}
|
||||
|
||||
if (!fontFamily) {
|
||||
fontFamily = viewFont.fontName;
|
||||
}
|
||||
|
||||
let font;
|
||||
|
||||
let fontDescriptor: UIFontDescriptor = viewFont.fontDescriptor;
|
||||
if (fontFamily) {
|
||||
fontDescriptor = fontDescriptor.fontDescriptorWithFamily(fontFamily);
|
||||
}
|
||||
|
||||
let symbolicTraits;
|
||||
if (bold) {
|
||||
symbolicTraits |= UIFontDescriptorSymbolicTraits.TraitBold;
|
||||
}
|
||||
|
||||
if (italic) {
|
||||
symbolicTraits |= UIFontDescriptorSymbolicTraits.TraitItalic;
|
||||
}
|
||||
|
||||
if (symbolicTraits) {
|
||||
font = UIFont.fontWithDescriptorSize(fontDescriptor.fontDescriptorWithSymbolicTraits(symbolicTraits), fontSize);
|
||||
} else {
|
||||
font = UIFont.fontWithDescriptorSize(fontDescriptor, fontSize);
|
||||
}
|
||||
|
||||
attrDict[NSFontAttributeName] = font;
|
||||
let font = new Font(style.fontFamily, style.fontSize, style.fontStyle, style.fontWeight);
|
||||
let iosFont = font.getUIFont(viewFont);
|
||||
attrDict[NSFontAttributeName] = iosFont;
|
||||
}
|
||||
|
||||
const color = span.color;
|
||||
|
Reference in New Issue
Block a user