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" />
|
<Label text="" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" />
|
||||||
<Button text="TAP" tap="onTap">
|
<Button text="TAP" tap="onTap">
|
||||||
<FormattedString>
|
<FormattedString>
|
||||||
<Span text="" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
<Span text="" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||||
<Span text="font-awesome" fontAttributes="Bold"></Span>
|
<Span text="font-awesome" fontWeight="bold"></Span>
|
||||||
</FormattedString>
|
</FormattedString>
|
||||||
</Button>
|
</Button>
|
||||||
<Button text="TAP" tap="onTap" class="">
|
<Button text="TAP" tap="onTap" class="">
|
||||||
<FormattedString>
|
<FormattedString>
|
||||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||||
<Span text="some text" fontAttributes="Bold"></Span>
|
<Span text="some text" fontWeight="bold"></Span>
|
||||||
</FormattedString>
|
</FormattedString>
|
||||||
</Button>
|
</Button>
|
||||||
<Button text="TAP" tap="onTap" class="">
|
<Button text="TAP" tap="onTap" class="">
|
||||||
<FormattedString>
|
<FormattedString>
|
||||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||||
<Span text="some text" fontAttributes="Bold"></Span>
|
<Span text="some text" fontWeight="bold"></Span>
|
||||||
</FormattedString>
|
</FormattedString>
|
||||||
</Button>
|
</Button>
|
||||||
<Button text="TAP" tap="onTap" class="">
|
<Button text="TAP" tap="onTap" class="">
|
||||||
<FormattedString>
|
<FormattedString>
|
||||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||||
<Span text="some text" fontAttributes="Bold"></Span>
|
<Span text="some text" fontWeight="bold"></Span>
|
||||||
</FormattedString>
|
</FormattedString>
|
||||||
</Button>
|
</Button>
|
||||||
<Button text="TAP" tap="onTap" class="">
|
<Button text="TAP" tap="onTap" class="">
|
||||||
<FormattedString>
|
<FormattedString>
|
||||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||||
<Span text="some text" fontAttributes="Bold"></Span>
|
<Span text="some text" fontWeight="bold"></Span>
|
||||||
</FormattedString>
|
</FormattedString>
|
||||||
</Button>
|
</Button>
|
||||||
<Button text="TAP" tap="onTap" class="">
|
<Button text="TAP" tap="onTap" class="">
|
||||||
<FormattedString>
|
<FormattedString>
|
||||||
<Span text="" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span>
|
<Span text="" fontFamily="FontAwesome" fontSize="42em" color="white"></Span>
|
||||||
<Span text="some text" fontAttributes="Bold"></Span>
|
<Span text="some text" fontWeight="bold"></Span>
|
||||||
</FormattedString>
|
</FormattedString>
|
||||||
</Button>
|
</Button>
|
||||||
<Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
|
<Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Definitions.
|
// Definitions.
|
||||||
import { TextBase as TextBaseDefinition } from ".";
|
import { TextBase as TextBaseDefinition } from ".";
|
||||||
import { FontWeight } from "../styling/font";
|
import { FontStyle, FontWeight } from "../styling/font";
|
||||||
import { PropertyChangeData } from "../../data/observable";
|
import { PropertyChangeData } from "../../data/observable";
|
||||||
|
|
||||||
// Types.
|
// Types.
|
||||||
@ -19,6 +19,13 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition
|
|||||||
public text: string;
|
public text: string;
|
||||||
public formattedText: FormattedString;
|
public formattedText: FormattedString;
|
||||||
|
|
||||||
|
get fontFamily(): string {
|
||||||
|
return this.style.fontFamily;
|
||||||
|
}
|
||||||
|
set fontFamily(value: string) {
|
||||||
|
this.style.fontFamily = value;
|
||||||
|
}
|
||||||
|
|
||||||
get fontSize(): number {
|
get fontSize(): number {
|
||||||
return this.style.fontSize;
|
return this.style.fontSize;
|
||||||
}
|
}
|
||||||
@ -26,6 +33,20 @@ export abstract class TextBaseCommon extends View implements TextBaseDefinition
|
|||||||
this.style.fontSize = value;
|
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 {
|
get letterSpacing(): number {
|
||||||
return this.style.letterSpacing;
|
return this.style.letterSpacing;
|
||||||
}
|
}
|
||||||
|
@ -234,37 +234,9 @@ export class TextBase extends TextBaseCommon {
|
|||||||
let fontSize = span.fontSize;
|
let fontSize = span.fontSize;
|
||||||
|
|
||||||
if (bold || italic || fontFamily || fontSize) {
|
if (bold || italic || fontFamily || fontSize) {
|
||||||
if (!fontSize) {
|
let font = new Font(style.fontFamily, style.fontSize, style.fontStyle, style.fontWeight);
|
||||||
fontSize = viewFont.pointSize;
|
let iosFont = font.getUIFont(viewFont);
|
||||||
}
|
attrDict[NSFontAttributeName] = iosFont;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const color = span.color;
|
const color = span.color;
|
||||||
|
Reference in New Issue
Block a user