Question

I have a custom UISegmentedControl Object, it shows like

#import "redSegmentedControl.h"

@implementation redSegmentedControl

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code

        [self setBackgroundImage:[UIImage imageNamed:@"nev.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [self setBackgroundImage:[[UIImage imageNamed:@"nev_hover.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

        [self setDividerImage:[UIImage imageNamed:@"nev_sep.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [self setDividerImage:[UIImage imageNamed:@"nev_sep.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
        [self setDividerImage:[UIImage imageNamed:@"nev_sep.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault];

        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"nev_hover.png"]];

        NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"LatinBold13" size:bool_isEnglish?15.0f:10.0f], UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, [UIColor blackColor], UITextAttributeTextShadowColor, nil];

        [self setTitleTextAttributes:attributes forState:UIControlStateNormal];
        [self setTitleTextAttributes:attributes forState:UIControlStateSelected];
    }
    return self;
}

@end

After initialization, If I set ENGLISH text, it shows fine. As I put Arabic text, it breaks in to character wise.

[topMenu setTitle:@"Featured" forSegmentAtIndex:0];

[topMenu setTitle:@"متميز" forSegmentAtIndex:0];

Here ENGLISH TEXT shows perfect,but Arabic TEXT breaks character by character and shows like below image

enter image description here

I read Apple documentation, but nothing is there regarding String and its language. I removed extra formatting, but no use.

I notice that

    NSString * string  = @"االْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ"; //Any Arabic line
    NSLog(@"%@",string);

it looks fine in LOG, but as I put it on segment control, it breaks it into characters and display.

I also tried Encoding, but no use.

What expected cause can be, any help!!!!

Thanks

Was it helpful?

Solution

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:bool_isEnglish?15.0f:12.0f], UITextAttributeFont, [UIColor whiteColor], UITextAttributeTextColor, [UIColor blackColor], UITextAttributeTextShadowColor, nil];

Only the FONT NAME was creating issue. I changed it from "LatinBold13" to "Arial". Its working fine Now.

Thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top