我有一个uilabel进入我的iOS应用程序。我使用段落样式将属性文本应用于UIlabel。但我没有理解为什么没有适用于前4-5行的理由?然后所有打印都很好(见下面的截图)。请告诉我我做错了什么。
问题
我的代码 - DetailsViewController.m
#import "DetailsViewController.h"
@interface DetailsViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labelDescription;
@property (weak, nonatomic) IBOutlet UILabel *labelDetails;
@property (strong, nonatomic) NSMutableParagraphStyle *paragraphStyle;
@end
@implementation DetailsViewController
#pragma mark - lazy instantiation
- (NSMutableParagraphStyle *)paragraphStyle {
if (!_paragraphStyle) {
_paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[_paragraphStyle setAlignment:NSTextAlignmentJustified];
[_paragraphStyle setHyphenationFactor:1.0f];
[_paragraphStyle setLineSpacing:5.0f];
}
return _paragraphStyle;
}
#pragma mark - view controllers life cycle methods
- (void)viewDidLoad {
[super viewDidLoad];
[self.view layoutIfNeeded];
// updating fonts
[Utils updateLabelFontSize:self.labelDescription ForInitialHeight:20 andInitialSize:18];
[self.labelDetails setFont:[self.labelDetails.font fontWithSize:[self.labelDescription bounds].size.height * 0.85]];
// create labelText to.hFile
NSString *labelText = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
[attributedString addAttribute:NSParagraphStyleAttributeName value:self.paragraphStyle range:NSMakeRange(0, [labelText length])];
[self.labelDetails setAttributedText:attributedString];
}
@end
答案 0 :(得分:1)
试试这段代码:
<Window x:Class="MathEdit.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MathEdit"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.CommandBindings>
<CommandBinding Command="Open" Executed="OpenCommandBinding_Executed"></CommandBinding>
<CommandBinding Command="Save" Executed="SaveCommandBinding_Executed"></CommandBinding>
<CommandBinding Command="SaveAs" Executed="SaveAsCommandBinding_Executed"></CommandBinding>
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Key="O" Modifiers="Control" Command="Open"></KeyBinding>
<KeyBinding Key="S" Modifiers="Control" Command="Save"></KeyBinding>
<KeyBinding Key="S" Modifiers="Control+Alt" Command="SaveAs"></KeyBinding>
</Window.InputBindings>
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem Header="_New" InputGestureText="Ctrl+N" />
<MenuItem Header="_Open" InputGestureText="Ctrl+O" Command="Open"/>
<MenuItem Header="_Save" InputGestureText="Ctrl+S" Command="Save"/>
<MenuItem Header="_Save As" InputGestureText="Ctrl+Alt+S" Command="SaveAs"/>
<Separator />
<MenuItem Header="_Exit" InputGestureText="Alt+F4" />
</MenuItem>
<MenuItem Header="_Tools">
<MenuItem Header="_Check if toby = on" IsCheckable="false" IsChecked="True" Click="MenuItem_Click" />
<MenuItem Header="_Settings" Click="MenuItem_Click_2" IsCheckable="True" />
<MenuItem Header="_Add formula" x:Name="menuItemAdd" Click="MenuItem_Add_Click" />
</MenuItem>
<ComboBox x:Name="fontSizeBox" Width="40" SelectedValuePath="Content" SelectionChanged="fontSizeBox_SelectionChanged" SelectedIndex="2">
<ComboBoxItem Content="5"/>
<ComboBoxItem Content="12"/>
<ComboBoxItem Content="16"/>
<ComboBoxItem Content="20"/>
</ComboBox>
</Menu>
<Grid x:Name="gridParent">
<RichTextBox x:Name="richTextBox" AcceptsReturn="True" SelectionChanged="textBoxMain_SelectionChanged" />
</Grid>
</DockPanel>