FontAwesome will now work in iOS buttons, being bold will fallback to Helvetica

This commit is contained in:
Panayot Cankov
2017-03-15 13:57:27 +02:00
parent 7b5ef052fd
commit 01368d4bb5
3 changed files with 37 additions and 44 deletions

View File

@ -8,38 +8,38 @@
<Label text="&#xf0a1;" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" /> <Label text="&#xf0a1;" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" />
<Button text="TAP" tap="onTap"> <Button text="TAP" tap="onTap">
<FormattedString> <FormattedString>
<Span text="&#xf0a1;" class="font-awesome" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span> <Span text="&#xf0a1;" 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="&#xf1ec;" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span> <Span text="&#xf1ec;" 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="&#xf017;" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span> <Span text="&#xf017;" 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="&#xf1b9;" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span> <Span text="&#xf1b9;" 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="&#xf075;" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span> <Span text="&#xf075;" 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="&#xf05a;" fontFamily="FontAwesome" fontSize="42em" foregroundColor="white" fontAttributes="Bold"></Span> <Span text="&#xf05a;" 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"/>

View File

@ -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;
} }

View File

@ -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;