Hi everyone,
i’m making a custom cell in which, programmatically, I’m adding some labels and its constraints. But I’ve a problem.
in this app that i’m developing, there is a view that show the app’s settings. these settings are only about language. A user can decide if a word can be shown in all available language or choose which language activate and which switch off.
for example you can choose between english, french, spanish, german. default this value are on, available. so you can see the word also in this languages. Now the problem, i want that if I switch off, for example, spanish, you see the word in english, french and german; Or, if I switch off english and french, you can see the word in spanish and german language but not in english and french; and so on.
Have any idea about how can I do this programmatically?
my cell is this:
one note: for may app Kanji, Furigana, Romaji and Italian are locked. what change is English and other language. Actually i’ll have only english but i won’t in the future add other languages.
`CGRect imageViewJapRect = CGRectMake(16, 14, 25, 25);
_imageViewJap = [[UIImageView alloc] initWithFrame:imageViewJapRect];
[_imageViewJap setImage:[UIImage imageNamed:@“jp.png”]];
[_imageViewJap setBackgroundColor:[UIColor redColor]];
_imageViewJap.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_imageViewJap];
CGRect textFuriganaLabelRect = CGRectMake(57, 8, 510, 21);
_textFuriganaLabel = [[UILabel alloc] initWithFrame:textFuriganaLabelRect];
[_textFuriganaLabel setBackgroundColor:[UIColor greenColor]];
_textFuriganaLabel.textAlignment = NSTextAlignmentLeft;
_textFuriganaLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_textFuriganaLabel];
CGRect textKanjiLabelRect = CGRectMake(57, 27, 510, 21);
_textKanjiLabel = [[UILabel alloc]initWithFrame:textKanjiLabelRect];
[_textKanjiLabel setBackgroundColor:[UIColor orangeColor]];
_textKanjiLabel.textAlignment = NSTextAlignmentLeft;
_textKanjiLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_textKanjiLabel];
CGRect imageViewRomajiRect = CGRectMake(16, 56, 25, 25);
_imageViewRomaji = [[UIImageView alloc]initWithFrame:imageViewRomajiRect];
[_imageViewRomaji setImage:[UIImage imageNamed:@"Translation-Icon.jpg"]];
[_imageViewRomaji setBackgroundColor:[UIColor blueColor]];
_imageViewRomaji.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_imageViewRomaji];
CGRect textRomajiLabelRect = CGRectMake(57, 58, 510, 21);
_textRomajiLabel = [[UILabel alloc]initWithFrame:textRomajiLabelRect];
_textRomajiLabel.textAlignment = NSTextAlignmentLeft;
[_textRomajiLabel setBackgroundColor:[UIColor lightGrayColor]];
_textRomajiLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_textRomajiLabel];
CGRect imageViewItaRect = CGRectMake(16, 89, 25, 25);
_imageViewIta = [[UIImageView alloc]initWithFrame:imageViewItaRect];
[_imageViewIta setImage:[UIImage imageNamed:@"it.png"]];
[_imageViewIta setBackgroundColor:[UIColor purpleColor]];
_imageViewIta.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_imageViewIta];
CGRect textItaLabelRect = CGRectMake(57, 91, 510, 21);
_textItaLabel = [[UILabel alloc]initWithFrame:textItaLabelRect];
_textItaLabel.textAlignment = NSTextAlignmentLeft;
[_textItaLabel setBackgroundColor:[UIColor brownColor]];
_textItaLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_textItaLabel];
CGRect imageViewEnRect = CGRectMake(16, 122, 25, 25);
_imageViewEn = [[UIImageView alloc]initWithFrame:imageViewEnRect];
[_imageViewEn setImage:[UIImage imageNamed:@"en.png"]];
[_imageViewEn setBackgroundColor:[UIColor yellowColor]];
_imageViewEn.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_imageViewEn];
CGRect textEnLabelRect = CGRectMake(57, 124, 510, 21);
_textEnLabel = [[UILabel alloc]initWithFrame:textEnLabelRect];
_textEnLabel.textAlignment = NSTextAlignmentLeft;
[_textEnLabel setBackgroundColor:[UIColor purpleColor]];
_textEnLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_textEnLabel];
NSDictionary *viewDictionary = @{@"imageJap":_imageViewJap, @"textKanji":_textKanjiLabel, @"textFurigana":_textFuriganaLabel, @"imageRomaji":_imageViewRomaji, @"textRomaji":_textRomajiLabel, @"imageIta":_imageViewIta, @"textIta":_textItaLabel, @"imageEn":_imageViewEn, @"textEn":_textEnLabel};
NSArray *imageJap_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageJap(25)]" options:0 metrics:nil views:viewDictionary];
NSArray *imageJap_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageJap(25)]" options:0 metrics:nil views:viewDictionary];
NSArray *imageJap_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-16-[imageJap]" options:0 metrics:nil views:viewDictionary];
NSArray *imageJap_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-14-[imageJap]" options:0 metrics:nil views:viewDictionary];
NSArray *textFurigana_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageJap]-16-[textFurigana]-2-|" options:0 metrics:nil views:viewDictionary];
NSArray *textFurigana_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-8-[textFurigana]" options:0 metrics:nil views:viewDictionary];
NSArray *textKanji_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageJap]-16-[textKanji]-2-|" options:0 metrics:nil views:viewDictionary];
NSArray *textKanji_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-27-[textKanji]" options:0 metrics:nil views:viewDictionary];
NSArray *imageRomaji_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageRomaji(25)]" options:0 metrics:nil views:viewDictionary];
NSArray *imageRomaji_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageRomaji(25)]" options:0 metrics:nil views:viewDictionary];
NSArray *imageRomaji_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-16-[imageRomaji]" options:0 metrics:nil views:viewDictionary];
NSArray *imageRomaji_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageJap]-17-[imageRomaji]" options:0 metrics:nil views:viewDictionary];
NSArray *textRomaji_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageRomaji]-16-[textRomaji]-2-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:viewDictionary];
NSArray *textRomaji_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[textKanji]-10-[textRomaji]" options:0 metrics:nil views:viewDictionary];
NSArray *imageITA_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageIta(25)]" options:0 metrics:nil views:viewDictionary];
NSArray *imageITA_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageIta(25)]" options:0 metrics:nil views:viewDictionary];
NSArray *imageITA_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-16-[imageIta]" options:0 metrics:nil views:viewDictionary];
NSArray *imageITA_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageRomaji]-8-[imageIta]" options:0 metrics:nil views:viewDictionary];
NSArray *textITA_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageIta]-16-[textIta]-2-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:viewDictionary];
NSArray *textITA_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[textRomaji]-12-[textIta]" options:0 metrics:nil views:viewDictionary];
NSArray *imageEN_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageEn(25)]" options:0 metrics:nil views:viewDictionary];
NSArray *imageEN_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageEn(25)]" options:0 metrics:nil views:viewDictionary];
NSArray *imageEN_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-16-[imageEn]" options:0 metrics:nil views:viewDictionary];
NSArray *imageEN_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[imageIta]-8-[imageEn]-8-|" options:0 metrics:nil views:viewDictionary];
NSArray *textEN_POS_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageEn]-16-[textEn]-2-|" options:NSLayoutFormatAlignAllCenterY metrics:nil views:viewDictionary];
NSArray *textEN_POS_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[textIta]-12-[textEn]-10-|" options:0 metrics:nil views:viewDictionary];
[self.imageViewJap addConstraints:imageJap_H];
[self.imageViewJap addConstraints:imageJap_V];
[self.contentView addConstraints:imageJap_POS_H];
[self.contentView addConstraints:imageJap_POS_V];
[self.contentView addConstraints:textFurigana_POS_H];
[self.contentView addConstraints:textFurigana_POS_V];
[self.contentView addConstraints:textKanji_POS_H];
[self.contentView addConstraints:textKanji_POS_V];
[self.imageViewRomaji addConstraints:imageRomaji_H];
[self.imageViewRomaji addConstraints:imageRomaji_V];
[self.contentView addConstraints:imageRomaji_POS_H];
[self.contentView addConstraints:imageRomaji_POS_V];
[self.contentView addConstraints:textRomaji_POS_H];
[self.contentView addConstraints:textRomaji_POS_V];
[self.imageViewIta addConstraints:imageITA_H];
[self.imageViewIta addConstraints:imageITA_V];
[self.contentView addConstraints:imageITA_POS_H];
[self.contentView addConstraints:imageITA_POS_V];
[self.contentView addConstraints:textITA_POS_H];
[self.contentView addConstraints:textITA_POS_V];
[self.imageViewEn addConstraints:imageEN_H];
[self.imageViewEn addConstraints:imageEN_V];
[self.contentView addConstraints:imageEN_POS_H];
[self.contentView addConstraints:imageEN_POS_V];
[self.contentView addConstraints:textEN_POS_H];
[self.contentView addConstraints:textEN_POS_V];`