Использовать протокол UIAppearance
. Сделайте больше хаков с appearanceFont
, чтобы изменить шрифт для UIAlertAction
.
Создайте категорию для UILabel
UILabel + FontAppearance.h
@interface UILabel (FontAppearance)
@property (nonatomic, copy) UIFont * appearanceFont UI_APPEARANCE_SELECTOR;
@end
UILabel + FontAppearance.m
@implementation UILabel (FontAppearance)
- (void)setAppearanceFont:(UIFont *)font
{
if (self.tag == 1001) {
return;
}
BOOL isBold = (self.font.fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold);
const CGFloat* colors = CGColorGetComponents(self.textColor.CGColor);
if (self.font.pointSize == 14) {
// set font for UIAlertController title
self.font = [UIFont systemFontOfSize:11];
} else if (self.font.pointSize == 13) {
// set font for UIAlertController message
self.font = [UIFont systemFontOfSize:11];
} else if (isBold) {
// set font for UIAlertAction with UIAlertActionStyleCancel
self.font = [UIFont systemFontOfSize:12];
} else if ((*colors) == 1) {
// set font for UIAlertAction with UIAlertActionStyleDestructive
self.font = [UIFont systemFontOfSize:13];
} else {
// set font for UIAlertAction with UIAlertActionStyleDefault
self.font = [UIFont systemFontOfSize:14];
}
self.tag = 1001;
}
- (UIFont *)appearanceFont
{
return self.font;
}
@end
Использование:
добавить
[[UILabel appearanceWhenContainedIn:UIAlertController.class, nil] setAppearanceFont:nil];
в AppDelegate.m
, чтобы сделать это работа для всех UIAlertController
.
Используйте .toggle () в jquery
$("#btnsearch").click(function () {
$("#Show").toggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" id="btnsearch" style="background-color: white">Search</button>
<div id="Show">ff</div>
Вы можете использовать функцию jquery toggle () для задачи
$("#btnsearch").click(function(){
$("#Show").toggle();
});
. С помощью функции jquery toggle () автоматически скрыть и показать целевой элемент #Show
Попробуйте это
$(document).ready(function(){
$("button").click(function(){
$("#toggle").toggle();
});
});
div {
height:200px;
width:200px;
background-color:red;
}
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div id="toggle">
</div>
<button>Toggle between hide() and show()</button>
</body>
</html>