Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Alignment issue when I set the custom font

When I set the custom font for the segmented control then it changes the vertical text alignment. I am using below code to set the font .

    // I dont think these lines are creating any issue but just wanted to paste all the code
   self.segmentType.layer.borderColor = navigationTintColor.CGColor;
   self.segmentType.layer.cornerRadius = 0.0;
   self.segmentType.layer.borderWidth = 1.5;

   // These are the lines that are changing the text alignment
    UIFont *font = [UIFont fontWithName:ftHelveticaNeueLTPro_Th size:13.5];        
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                           forKey:UITextAttributeFont];
    [self.segmentType setTitleTextAttributes:attributes
                                     forState:UIControlStateNormal];

Here is the screenshot of whats is happening . If you observer, the text is not vertically centre aligned .

enter image description here

Please help me . Thank you in advance !!

like image 864
Bharat Jagtap Avatar asked Feb 24 '14 06:02

Bharat Jagtap


1 Answers

The below code suggested by @Emmanuel works perfectly fine. You can change the vertical offset to align the text vertically at the center .

 [self.segmentType setContentPositionAdjustment:UIOffsetMake(0, 2) forSegmentType:UISegmentedControlSegmentAny barMetrics:UIBarMetricsDefault];
like image 76
Bharat Jagtap Avatar answered Nov 06 '22 06:11

Bharat Jagtap